class VirtualTime
- VirtualTime
 - Reference
 - Object
 
Included Modules
- Comparable(Time)
 - YAML::Serializable
 
Defined in:
virtualtime.crConstant Summary
- 
        VERSION = 
[VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION].join('.') - 
        VERSION_MAJOR = 
1 - 
        VERSION_MINOR = 
2 - 
        VERSION_REVISION = 
3 
Constructors
- .new(year : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, month : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, day : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, week : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, day_of_week : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, day_of_year : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, hour : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, minute : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, second : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, millisecond : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, nanosecond : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, location : Nil | Time::Location, default_match : Bool = true)
 - .new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
 - .new(year : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, month : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, day : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, hour : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, minute : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, second : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, *, millisecond : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, nanosecond : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, day_of_week : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, day_of_year : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, week : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, location : Nil | Time::Location = nil, default_match : Bool = true)
 - .new(*, year : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, week : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, day_of_week : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, hour : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, minute : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, second : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, millisecond : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, nanosecond : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Set(Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, location : Nil | Time::Location = ni, default_match : Bool = true)
 
Class Method Summary
- 
        .from_time(time : Time, *, milliseconds = false, nanoseconds = true)
        
          
Creates
VirtualTimefromTime. 
Instance Method Summary
- 
        #<=>(other : Time)
        
          
Compares
VirtualTimetoTimeinstance - 
        #==(other : self)
        
          
Returns
trueif this reference is the same as other. - 
        #==(time : TimeOrVirtualTime)
        
          
Compares
VirtualTimetoTimeinstance - 
        #adjust_day(day : Int, acceptable_day : Int, wrap_day : Int)
        
          
"Rewinds"
#dayforward enough to reachacceptable_day. - 
        #adjust_location(time)
        
          
Ensures that
Time's timezone is equal to VT's timezone. - 
        #adjust_value(a, max)
        
          
Adjusts values to be suitable for use in comparisons.
 - 
        #clear!
        
          
Sets all fields to nil
 - 
        #clear_date!
        
          
Sets date-related fields to nil
 - 
        #clear_time!
        
          
Sets time-related fields to nil
 - #day : Virtual
 - #day=(day : Virtual)
 - #day_of_week : Virtual
 - #day_of_week=(day_of_week : Virtual)
 - #day_of_year : Virtual
 - #day_of_year=(day_of_year : Virtual)
 - 
        #default_match=(default_match : Bool)
        
          
Instance-default match result if one of field values matched is
nil - 
        #default_match? : Bool
        
          
Instance-default match result if one of field values matched is
nil - 
        #expand
        
          
Expands VirtualTime containing ranges or lists into a list of individual VirtualTimes with specific values E.g.
 - #hour : Virtual
 - #hour=(hour : Virtual)
 - #location : Time::Location | Nil
 - #location=(location : Time::Location | Nil)
 - 
        #matches?(a, b, max = nil) : Bool
        
          
Performs matching between VirtualTime and other supported types
 - 
        #matches?(time : TimeOrVirtualTime = Time.local)
        
          
Returns whether
VirtualTimematches the specified time - 
        #matches_date?(time : TimeOrVirtualTime = Time.local)
        
          
Returns whether
VirtualTimematches the date part of specified time - 
        #matches_time?(time : TimeOrVirtualTime = Time.local)
        
          
Returns whether
VirtualTimematches the time part of specified time - 
        #materialize(allowed, wanted : Int, min, max = nil, strict = true)
        
          
Materialize a particular value with the help of a wanted/wanted value.
 - 
        #materialize(hint = Time.local.at_beginning_of_minute, strict = true)
        
          
Returns a new, "materialized" VirtualTime, i.e.
 - 
        #materialize_date_with_hint(time : Time = Time.local.at_beginning_of_minute, carry = 0)
        
          
Materialize date part of current VT
 - 
        #materialize_time_with_hint(time : Time = Time.local.at_beginning_of_minute, carry = 0)
        
          
Materialize time part of current VT
 - 
        #materialize_with_hint(time : Time = Time.local.at_beginning_of_minute, carry = 0)
        
          
Materializes VT and returns fields needed to create a
Timeobject. - #millisecond : Virtual
 - #millisecond=(millisecond : Virtual)
 - #minute : Virtual
 - #minute=(minute : Virtual)
 - #month : Virtual
 - #month=(month : Virtual)
 - #nanosecond : Virtual
 - #nanosecond=(nanosecond : Virtual)
 - #second : Virtual
 - #second=(second : Virtual)
 - 
        #step(interval = 1.minute, by = 1, from = Time.local.at_end_of_minute) : Iterator
        
          
Returns Iterator
 - 
        #succ(from : Time = Time.local.at_end_of_minute)
        
          
Produces closest-next
Timethat matches the current VT, starting withfrom+ 1 nanosecond onwards - 
        #to_time(hint = Time.local.at_beginning_of_minute, strict = true)
        
          
Converts a VirtualTime to a specific Time object that matches the VirtualTime.
 - 
        #to_tuple
        
          
Outputs VirtualTime instance as a tuple with signature
Tuple(11x Virtual, Time::Location?) - #week : Virtual
 - #week=(week : Virtual)
 - #year : Virtual
 - #year=(year : Virtual)
 
Macro Summary
- 
        adjust_wanted_re_max
        
          
If
maxis specified, adjustshintin respect tomax. - 
        virtual_time_property(*properties)
        
          
Macro to define properties with a common YAML converter
 
Constructor Detail
Class Method Detail
Creates VirtualTime from Time.
This can be useful to produce a VT with many fields filled in quickly, and then set fields of choice to more interesting values rather than fixed integers.
Note that this copies all values from Time to VirtualTime, including week number, day of week, day of year.
That results in a very fixed VirtualTime which is probably not useful unless some values are afterwards reset to nil or set to other VT-specific options.
Millisecond and nanosecond values are copied from Time into VirtualTime only if options milliseconds= and nanoseconds= are set to true.
Default is currently true for nanoseconds.
Whether these options are useful, or whether they should be removed, or whether all fields should get a corresponding option like this, remains be seen.
Instance Method Detail
Returns true if this reference is the same as other. Invokes same?.
"Rewinds" #day forward enough to reach acceptable_day.
It wraps around wrap_day, so e.g. #adjust_day(25, 5, 30) returns 10.days
Ensures that Time's timezone is equal to VT's timezone.
Raises ArgumentError if comparing two VTs with different timezones.
Adjusts values to be suitable for use in comparisons.
At the moment, that includes converting negative values to offsets from end of range, reorganizing ranges so ttat begin <= end, and sorting Arrays and Sets,
If calling this function yourself, provide max whenever possible.
Instance-default match result if one of field values matched is nil
Expands VirtualTime containing ranges or lists into a list of individual VirtualTimes with specific values
E.g. VirtualTime with day=1..2 gets expanded into two separate VirtualTimes, day=1 and day=2
This function is used only in tests.
Performs matching between VirtualTime and other supported types
Returns whether VirtualTime matches the specified time
Returns whether VirtualTime matches the date part of specified time
Returns whether VirtualTime matches the time part of specified time
Materialize a particular value with the help of a wanted/wanted value. If 'strict' is true and wanted value does not satisfy predefined range or requirements, it is replaced with the first/earliest value from allowed range.
Returns a new, "materialized" VirtualTime, i.e. an object where all fields have "materialized"/specific values
Materialize date part of current VT
Materialize time part of current VT
Materializes VT and returns fields needed to create a Time object.
This function does not check that the materialized values match the week number, day of week, and day of year constraints.
If you need those values checked, use #to_time.
Returns Iterator
Produces closest-next Time that matches the current VT, starting with from + 1 nanosecond onwards
Converts a VirtualTime to a specific Time object that matches the VirtualTime.
Value is converted using a time hint, which defaults to the current time. Lists and ranges of values materialize to their min / begin value.
Additionally, any requirements for week number, day of week, and day of year are also met, possibly by doing multiple iterations to find a suitable date. The process is limited to some max attempts of trying to find a value that simultaneously satisfies all constraints.
Outputs VirtualTime instance as a tuple with signature Tuple(11x Virtual, Time::Location?)
Macro Detail
If max is specified, adjusts hint in respect to max.
Specifically, if hint is equal or greater than max, it wraps it around
by increasing carry by 1 and reducing hint by max.
The current implementation does not support wrapping more than once, e.g.
a wanted of 120 with a max of 60 would produce an error.
That is because some of VirtualTimes fields (like e.g. #day) do not have
a fixed max value (it can be 28, 29, 30, or 31, depending on month).