struct Cronus::Date
- Cronus::Date
- Struct
- Value
- Object
Overview
A really, really simple Gregorian Date
Included Modules
- Comparable(Cronus::Date)
Defined in:
cronus/date.crConstant Summary
-
DAYS_OF_THE_MONTH =
{Month::January => 31, Month::February => 28, Month::March => 31, Month::April => 30, Month::May => 31, Month::June => 30, Month::July => 31, Month::August => 31, Month::September => 30, Month::October => 31, Month::November => 30, Month::December => 31}
Constructors
-
.new(year : Int, month : Int, day : Int)
Date.new(2011, 1, 16)
-
.new(parser : JSON::PullParser)
Provide Object.from_json support.
Class Method Summary
- .from_json(pull : JSON::PullParser)
- .leap_year?(year : Int)
-
.parse(s : String)
Parses an ISO 8601 date string of the format: YYYY-MM-DD
Instance Method Summary
-
#<=>(other : Date)
The comparison operator.
- #day : Int8
-
#inspect(io : IO)
Appends this struct's name and instance variables names and values to the given IO.
- #iso8601 : String
- #month : Cronus::Date::Month
- #to_json(builder : JSON::Builder)
-
#to_s(io : IO)
Same as
#inspect(io)
. - #year : Int16
Constructor Detail
Provide Object.from_json support. See https://github.com/crystal-lang/crystal/blob/master/src/json/from_json.cr
Class Method Detail
Instance Method Detail
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]
Appends this struct's name and instance variables names and values to the given IO.
struct Point
def initialize(@x : Int32, @y : Int32)
end
end
p1 = Point.new 1, 2
p1.to_s # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"