Class: Synthra::Types::DateTime::DateType
- Defined in:
- lib/synthra/types/date_time/dates.rb
Overview
DateType type
Instance Method Summary collapse
- #generate_edge(rng, context, args) ⇒ Object
- #generate_invalid(rng, context, args) ⇒ Object
- #generate_random(rng, context, args) ⇒ Object
Instance Method Details
#generate_edge(rng, context, args) ⇒ Object
28 29 30 31 |
# File 'lib/synthra/types/date_time/dates.rb', line 28 def generate_edge(rng, context, args) anchor = TimeTravel.anchor_date || Date.today [anchor, anchor - 730].sample(random: rng.instance_variable_get(:@random)) end |
#generate_invalid(rng, context, args) ⇒ Object
33 34 35 |
# File 'lib/synthra/types/date_time/dates.rb', line 33 def generate_invalid(rng, context, args) [nil, "not a date", 123, [], {}].sample(random: rng.instance_variable_get(:@random)) end |
#generate_random(rng, context, args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/synthra/types/date_time/dates.rb', line 8 def generate_random(rng, context, args) # When a TimeTravel context is active, re-base the "N days back from today" # distribution onto the anchor date instead of the real Date.today. Same # shape (uniform over the last 2 years), just relative to a different origin. anchor = TimeTravel.anchor_date return anchor - rng.int(0, 730) if anchor adapter = faker_adapter(context) if adapter adapter.date_backward(days: 365 * 2) else Faker::Date.backward(days: 365 * 2) end rescue StandardError Date.today - rng.int(0, 730) end |