Class: Hegel::Generators::DatetimesGenerator
- Inherits:
-
Hegel::Generator
- Object
- Hegel::Generator
- Hegel::Generators::DatetimesGenerator
- Defined in:
- lib/hegel/generators.rb,
sig/hegel.rbs
Overview
Hegel::Syntax::Methods#datetimes. A naive (no timezone) Time in [min_value, max_value], defaulting to the conventional full range (0001-01-01T00:00:00.000000 through 9999-12-31T23:59:59.999999 -- hegel-rust's own full_ranges::MIN_DATETIME/MAX_DATETIME) when either bound is omitted.
Built with Time.utc, not Time.new/Time.local: the drawn value has no timezone of its own (hegel.h calls hegel_datetime_t "a date plus a time of day, no timezone"), and UTC is the one zone every machine running this gem's own tests agrees on, so a drawn value's own year/month/day/hour/min/sec/usec read back exactly the fields that were drawn, not shifted by whatever zone the process happens to run in. min_value/max_value are read the same way: #do_draw takes whatever zone the caller's own Time is already in at face value (its own #year/#month/#day/#hour/#min/#sec/#usec), rather than converting to UTC first, so a caller who wants a specific wall-clock bound does not have to convert it themselves.
Opens no span, for the same reason DatesGenerator does not (one native call, HEGEL_LABEL_DATETIME sits below HEGEL_LABEL_REGEX in the same header list).
Constant Summary collapse
- MIN_DATETIME =
Time.utc(1, 1, 1, 0, 0, 0, 0)
- MAX_DATETIME =
Time.utc(9999, 12, 31, 23, 59, 59, 999_999)
Instance Method Summary collapse
- #do_draw(tc) ⇒ Time
-
#initialize(min_value:, max_value:) ⇒ DatetimesGenerator
constructor
A new instance of DatetimesGenerator.
Methods inherited from Hegel::Generator
Constructor Details
#initialize(min_value:, max_value:) ⇒ DatetimesGenerator
Returns a new instance of DatetimesGenerator.
723 724 725 726 727 |
# File 'lib/hegel/generators.rb', line 723 def initialize(min_value:, max_value:) super() @min_value = min_value @max_value = max_value end |
Instance Method Details
#do_draw(tc) ⇒ Time
729 730 731 732 733 734 735 736 737 738 739 740 741 |
# File 'lib/hegel/generators.rb', line 729 def do_draw(tc) min_value = @min_value || MIN_DATETIME max_value = @max_value || MAX_DATETIME raise Hegel::Error, "datetimes: max_value < min_value" if max_value < min_value date, time = tc.generate_datetime( [min_value.year, min_value.month, min_value.day], [min_value.hour, min_value.min, min_value.sec, min_value.usec], [max_value.year, max_value.month, max_value.day], [max_value.hour, max_value.min, max_value.sec, max_value.usec] ) Time.utc(*date, *time) end |