class Crystime::VirtualTime
- Crystime::VirtualTime
- Reference
- Object
Included Modules
- Comparable(Time)
- Comparable(Crystime::VirtualTime)
- YAML::Serializable
Defined in:
crystime/virtual_time.crConstructors
-
.new(year, month, day, hour = nil, minute = nil, second = nil, millisecond = nil)
Similar to Time constructor.
- .new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
-
.new
Empty constructor.
Class Method Summary
-
.[](date)
Parses string and produces VirtualTime.
- .from_array(arg)
- .local
Instance Method Summary
- #+(other : self)
-
#+(other : Time)
Btw, this is not supported with Time struct.
-
#+(other : Span | Time::Span)
XXX see what to do about this: after +, VT essentially becomes fully materialized, which isn't ideal
- #-(other : self)
- #-(other : Time)
-
#-(other : Span | Time::Span)
XXX add tests for @ts=[...] looking correct after VirtualTime+ Span
- #<=>(other : self)
-
#<=>(other : Time)
The comparison operator.
- #day : Virtual | Nil
- #day=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil)
- #day_of_week : Virtual | Nil
-
#day_of_week=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil)
Weekday does not affect actual date, only adds a constraint.
-
#dup
Returns a shallow copy of this object.
-
#expand
Expands a partial VirtualTime into a materialized/specific date/time.
-
#from_jd
Creates VirtualTime from Julian Day Number.
- #from_jd!
- #hour : Virtual | Nil
- #hour=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil)
- #jd : Virtual | Nil
-
#jd=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil)
Julian Day Number does affect actual date, but is not used in calculations.
-
#matches?(list : Array, default = true)
Checks if any element in list matches self.
- #matches?(t : Crystime::VirtualTime | Time, default = true)
- #materializable?
- #materialize!(hint = VirtualTime.new(1, 1, 1, 0, 0, 0, 0))
- #materialized?
-
#merge(other : self)
Merges a VT or Time into self.
- #millisecond : Virtual | Nil
- #millisecond=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil)
- #minute : Virtual | Nil
- #minute=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil)
- #month : Virtual | Nil
- #month=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil)
- #second : Virtual | Nil
- #second=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil)
- #to_array
-
#to_jd
Creates Julian Day Number from VirtualTime, when possible.
-
#to_time
Converts a VT to Time.
- #to_tuple
- #ts : Array(Bool?)
- #ts=(ts : Array(Bool | Nil))
-
#update!(jd = true)
Called when year, month, or day are re-set and we need to re-calculate which day_of_week and Julian Day Number the new date corresponds to.
- #year : Virtual | Nil
-
#year=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil)
XXX should boolean value be treated as materializable and have ts=true?
Constructor Detail
Similar to Time constructor. Fields are set via properties to trigger corresponding methods.
Empty constructor. Must be here since when fields are defined, the default empty constructor is not created.
Class Method Detail
Instance Method Detail
Btw, this is not supported with Time struct. (I.e. you can do Time-Time, but not Time+Time)
XXX see what to do about this: after +, VT essentially becomes fully materialized, which isn't ideal
XXX add tests for @ts=[...] looking correct after VirtualTime+ Span
The comparison operator. Returns 0
if the two objects are equal,
a negative number if this object is considered less than other,
a positive number if this object is considered greater than other,
or nil
if the two objects are not comparable.
Subclasses define this method to provide class-specific ordering.
The comparison operator is usually used to sort values:
# Sort in a descending way:
[3, 1, 2].sort { |x, y| y <=> x } # => [3, 2, 1]
# Sort in an ascending way:
[3, 1, 2].sort { |x, y| x <=> y } # => [1, 2, 3]
Weekday does not affect actual date, only adds a constraint.
Returns a shallow copy of this object.
This allocates a new object and copies the contents of
self
into it.
Julian Day Number does affect actual date, but is not used in calculations.
Checks if any element in list matches self.
Merges a VT or Time into self. Uses rule of left precedent (if self already has a value for a particular field, it is not overwritten). XXX possibly replace with macro? Possibly change logic?
Called when year, month, or day are re-set and we need to re-calculate which day_of_week and Julian Day Number the new date corresponds to. This is only filled if Y/m/d is specified. If it is not specified (meaning that the VirtualTime does not refer to a specific date), then they are set to nil. In the case where the change is caused by a jd that was just set, a 'jd: false' parameter could be passed not to touch jd again, even though there's no harm even if it is modified. XXX check whether update! is properly called (and/or code works correctly) when VTs are summed or subtracted.
XXX should boolean value be treated as materializable and have ts=true?