Class: Date

Inherits:
Object show all
Defined in:
lib/propr/random/date.rb,
lib/propr/shrink/date.rb

Constant Summary collapse

MIN =

0000-01-01

Date.jd(1721058)
MAX =

9999-12-31

Date.jd(5373484)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.random(options = {}, m = Propr::Random) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/propr/random/date.rb', line 7

def random(options = {}, m = Propr::Random)
  # These would be constants but `jd` is only defined
  # after `require "date"`.
  min = (options[:min] || MIN).jd
  max = (options[:max] || MAX).jd

  m.bind(Integer.random(options.merge(min: min, max: max))) do |n|
    m.unit(jd(n))
  end
end

Instance Method Details

#shrinkArray<Date>

Returns:



5
6
7
8
9
10
11
# File 'lib/propr/shrink/date.rb', line 5

def shrink
  Array.unfold(jd) do |seed|
    zero  = 2415021 # 1900-01-01
    seed_ = zero + (seed - zero) / 2
    (seed != seed_).maybe([self + zero - seed, seed_])
  end
end