class VirtualTime

Included Modules

Defined in:

virtualtime.cr

Constant Summary

VERSION = [VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION].join('.')
VERSION_MAJOR = 1
VERSION_MINOR = 1
VERSION_REVISION = 3

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(year : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, month : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, day : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, week : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, day_of_week : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, day_of_year : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, hour : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, minute : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, second : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, millisecond : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, nanosecond : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, location : Nil | Time::Location) #

[View source]
def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) #

[View source]
def self.new(year : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, month : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, day : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, hour : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, minute : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, second : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, *, millisecond : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, nanosecond : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, day_of_week : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, day_of_year : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, week : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil) #

[View source]
def self.new(*, year : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, week : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil, day_of_week : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, hour : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, minute : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, second : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, millisecond : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil, nanosecond : Array(Int32) | Bool | Int32 | Int32 -> Bool | Range(Int32, Int32) | Steppable::StepIterator(Int32, Int32, Int32) | Nil = nil) #

[View source]

Class Method Detail

def self.default_match=(default_match : Bool) #

Default match result if one of field values matched is nil


[View source]
def self.default_match? : Bool #

Default match result if one of field values matched is nil


[View source]
def self.from_time(time : Time, *, milliseconds = false, nanoseconds = true) #

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.


[View source]
def self.matches?(a : Nil, b, max = nil) #

Performs matching between VirtualTime and other supported types


[View source]
def self.matches?(a : Bool, b, max = nil) #

Performs matching between VirtualTime and other supported types


[View source]
def self.matches?(a : Int, b : Int, max = nil) #

Performs matching between VirtualTime and other supported types


[View source]
def self.matches?(a : Enumerable(Int), b : Int, max = nil) #

Performs matching between VirtualTime and other supported types


[View source]
def self.matches?(a : Enumerable(Int), b : Enumerable(Int), max = nil) #

Performs matching between VirtualTime and other supported types


[View source]
def self.matches?(a : Enumerable(Int), b : VirtualProc, max = nil) #

Performs matching between VirtualTime and other supported types


[View source]
def self.matches?(a : VirtualProc, b : Int, max = nil) #

Performs matching between VirtualTime and other supported types


[View source]
def self.matches?(a : VirtualProc, b : VirtualProc, max = nil) #

Performs matching between VirtualTime and other supported types


[View source]
def self.matches?(a, b, max = nil) #

[View source]
def self.materialize(value : Nil, default : Int32, max = nil, strict = true) #

Materialize a particular value with the help of a hint/default value. If 'strict' is true and default value does not satisfy predefined range or requirements, the default is replaced with the first/earliest value from allowed range.


[View source]
def self.materialize(value : Bool, default : Int32, max = nil, strict = true) #

Materialize a particular value with the help of a hint/default value. If 'strict' is true and default value does not satisfy predefined range or requirements, the default is replaced with the first/earliest value from allowed range.


[View source]
def self.materialize(value : Int, default : Int32, max = nil, strict = true) #

Materialize a particular value with the help of a hint/default value. If 'strict' is true and default value does not satisfy predefined range or requirements, the default is replaced with the first/earliest value from allowed range.


[View source]
def self.materialize(value : Enumerable(Int), default : Int32, max = nil, strict = true) #

Materialize a particular value with the help of a hint/default value. If 'strict' is true and default value does not satisfy predefined range or requirements, the default is replaced with the first/earliest value from allowed range.


[View source]
def self.materialize(value : Range(Int, Int), default : Int32, max = nil, strict = true) #

Materialize a particular value with the help of a hint/default value. If 'strict' is true and default value does not satisfy predefined range or requirements, the default is replaced with the first/earliest value from allowed range.


[View source]
def self.materialize(value : Proc(Virtual, Bool), default : Int32, max = nil, strict = true) #

Materialize a particular value with the help of a hint/default value. If 'strict' is true and default value does not satisfy predefined range or requirements, the default is replaced with the first/earliest value from allowed range.


[View source]

Instance Method Detail

def <=>(other : self) #

[View source]
def <=>(other : Time) #

Compares VirtualTime to Time instance


[View source]
def adjust_day(day : Int, acceptable_day : Int, wrap_day : Int) #

"Rewinds" #day forward enough to reach acceptable_day.

It wraps around wrap_day, so e.g. #adjust_day(25, 5, 30) returns 10.days


[View source]
def day : Virtual #

[View source]
def day=(day : Virtual) #

[View source]
def day_of_week : Virtual #

[View source]
def day_of_week=(day_of_week : Virtual) #

[View source]
def day_of_year : Virtual #

[View source]
def day_of_year=(day_of_year : Virtual) #

[View source]
def expand #

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


[View source]
def hour : Virtual #

[View source]
def hour=(hour : Virtual) #

[View source]
def location : Time::Location | Nil #

[View source]
def location=(location : Time::Location | Nil) #

[View source]
def matches?(time : TimeOrVirtualTime = Time.local) #

Returns whether VirtualTime matches the specified time


[View source]
def matches_date?(time : TimeOrVirtualTime = Time.local) #

Returns whether VirtualTime matches the date part of specified time


[View source]
def matches_time?(time : TimeOrVirtualTime = Time.local) #

Returns whether VirtualTime matches the time part of specified time


[View source]
def materialize(hint = Time.local, strict = true) #

Returns a new, "materialized" VirtualTime. I.e., it converts VirtualTime object to a Time-like value, where all fields have "materialized"/specific values


[View source]
def millisecond : Virtual #

[View source]
def millisecond=(millisecond : Virtual) #

[View source]
def minute : Virtual #

[View source]
def minute=(minute : Virtual) #

[View source]
def month : Virtual #

[View source]
def month=(month : Virtual) #

[View source]
def nanosecond : Virtual #

[View source]
def nanosecond=(nanosecond : Virtual) #

[View source]
def second : Virtual #

[View source]
def second=(second : Virtual) #

[View source]
def to_time(hint = Time.local, strict = true) #

Converts a VirtualTime to a specific Time object that hopefully 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 10 attempts of trying to find a value that simultaneously satisfies all constraints.


[View source]
def to_tuple #

Outputs VirtualTime instance as a tuple with signature Tuple(11x Virtual, Time::Location?)


[View source]
def week : Virtual #

[View source]
def week=(week : Virtual) #

[View source]
def year : Virtual #

[View source]
def year=(year : Virtual) #

[View source]