class Crystime::VirtualTime

Included Modules

Defined in:

crystime/virtual_time.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(year, month, day, hour = nil, minute = nil, second = nil, millisecond = nil) #

Similar to Time constructor. Fields are set via properties to trigger corresponding methods.


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

[View source]
def self.new #

Empty constructor. Must be here since when fields are defined, the default empty constructor is not created.


[View source]

Class Method Detail

def self.[](date) #

Parses string and produces VirtualTime.


[View source]
def self.from_array(arg) #

[View source]
def self.local #

[View source]

Instance Method Detail

def +(other : self) #

[View source]
def +(other : Time) #

Btw, this is not supported with Time struct. (I.e. you can do Time-Time, but not Time+Time)


[View source]
def +(other : Span | Time::Span) #

XXX see what to do about this: after +, VT essentially becomes fully materialized, which isn't ideal


[View source]
def -(other : self) #

[View source]
def -(other : Time) #

[View source]
def -(other : Span | Time::Span) #

XXX add tests for @ts=[...] looking correct after VirtualTime+ Span


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

[View source]
def <=>(other : Time) #
Description copied from module Comparable(Time)

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]

[View source]
def day : Virtual | Nil #

[View source]
def day=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil) #

[View source]
def day_of_week : Virtual | Nil #

[View source]
def day_of_week=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil) #

Weekday does not affect actual date, only adds a constraint.


[View source]
def dup #
Description copied from class Reference

Returns a shallow copy of this object.

This allocates a new object and copies the contents of self into it.


[View source]
def expand #

Expands a partial VirtualTime into a materialized/specific date/time.


[View source]
def from_jd #

Creates VirtualTime from Julian Day Number.


[View source]
def from_jd! #

[View source]
def hour : Virtual | Nil #

[View source]
def hour=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil) #

[View source]
def jd : Virtual | Nil #

[View source]
def jd=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil) #

Julian Day Number does affect actual date, but is not used in calculations.


[View source]
def matches?(list : Array, default = true) #

Checks if any element in list matches self.


[View source]
def matches?(t : Crystime::VirtualTime | Time, default = true) #

[View source]
def materializable? #

[View source]
def materialize!(hint = VirtualTime.new(1, 1, 1, 0, 0, 0, 0)) #

[View source]
def materialized? #

[View source]
def merge(other : 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?


[View source]
def millisecond : Virtual | Nil #

[View source]
def millisecond=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil) #

[View source]
def minute : Virtual | Nil #

[View source]
def minute=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil) #

[View source]
def month : Virtual | Nil #

[View source]
def month=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil) #

[View source]
def second : Virtual | Nil #

[View source]
def second=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil) #

[View source]
def to_array #

[View source]
def to_jd #

Creates Julian Day Number from VirtualTime, when possible. Raises otherwise.


[View source]
def to_time #

Converts a VT to Time. If VT is non-materializable, the process raises an exception.


[View source]
def to_tuple #

[View source]
def ts : Array(Bool?) #

[View source]
def ts=(ts : Array(Bool | Nil)) #

[View source]
def 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. 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.


[View source]
def year : Virtual | Nil #

[View source]
def year=(v : Bool | Enumerable(Int32) | Int32 | Int32 -> Bool | Nil) #

XXX should boolean value be treated as materializable and have ts=true?


[View source]