Class: Synthra::Types::DateTime::Now
- Defined in:
- lib/synthra/types/date_time/dates.rb
Overview
Now type
Instance Method Summary collapse
- #generate_edge(rng, context, args) ⇒ Object
- #generate_invalid(rng, context, args) ⇒ Object
-
#generate_random(rng, context, args) ⇒ Date
Generate a "current" date value.
Instance Method Details
#generate_edge(rng, context, args) ⇒ Object
187 188 189 190 191 192 193 194 |
# File 'lib/synthra/types/date_time/dates.rb', line 187 def generate_edge(rng, context, args) if TimeTravel.current_time anchored = TimeTravel.current_time.current_time return anchored.respond_to?(:to_date) ? anchored.to_date : anchored end [Date.new(2020, 1, 1), Date.new(2025, 1, 1)].sample(random: rng.instance_variable_get(:@random)) end |
#generate_invalid(rng, context, args) ⇒ Object
196 197 198 |
# File 'lib/synthra/types/date_time/dates.rb', line 196 def generate_invalid(rng, context, args) [nil, "not a date", 123, [], {}].sample(random: rng.instance_variable_get(:@random)) end |
#generate_random(rng, context, args) ⇒ Date
Generate a "current" date value
Uses a fixed base date (2020-01-01) plus a random offset determined by the RNG for deterministic output.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/synthra/types/date_time/dates.rb', line 171 def generate_random(rng, context, args) # "now" anchors exactly to the TimeTravel point-in-time when one is set — # it represents "the current moment", so under time travel that moment # IS the anchor (or a random point within an anchored range). if TimeTravel.current_time anchored = TimeTravel.current_time.current_time return anchored.respond_to?(:to_date) ? anchored.to_date : anchored end # Otherwise: use RNG to generate deterministic timestamps. # Base time is 2020-01-01, add random offset up to 5 years base_time = Date.new(2020, 1, 1) days_offset = rng.int(0, 365 * 5) base_time + days_offset end |