Date
A calendar date, with no time of day and no time zone.
To shift a date, use add_days and
sub_days -- a Duration cannot be
added to a Date.
Class Methods
from_ymd year month day -> Date
Builds a date from calendar components.
Parameters
| Name | Type | Description |
|---|---|---|
year |
Int |
Calendar year. |
month |
(Month | Int) |
Month, or its number from 1 through 12. |
day |
Int |
Day of month. |
Errors
| Exception | Condition |
|---|---|
TypeError |
An argument has the wrong type |
ValueError |
The month is out of range, or the components are not a real date |
Example
parse_rfc text -> Date
Parses an RFC full-date, YYYY-MM-DD.
Parameters
| Name | Type | Description |
|---|---|---|
text |
Str |
Date text. |
Errors
| Exception | Condition |
|---|---|
TypeError |
text is not a Str |
ValueError |
The input is not a valid YYYY-MM-DD date |
today() -> Date
Returns the current UTC date.
Fields
day @ IntDay of month.
month @ MonthCalendar month.
weekday @ WeekdayDay of week.
year @ IntCalendar year.
Methods
(eq) other
Compares two dates.
(hash)()
Hashes the value.
(lt) other
Orders two dates.
(str)()
Returns the YYYY-MM-DD form, as rfc does.
(sub) other -> Duration
Returns the Duration between the two dates' midnights.
The result is always a whole number of days.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Date |
Date to subtract. |
add_days days -> Date
Returns the date a signed number of days later.
Parameters
| Name | Type | Description |
|---|---|---|
days |
Int |
Days to add. May be negative. |
Errors
| Exception | Condition |
|---|---|
TypeError |
days is not an Int |
OverflowError |
The result is outside the supported range |
Example
datetime() -> DateTime
Returns midnight UTC on this date.
rfc() -> Str
Returns the RFC full-date representation, YYYY-MM-DD.
sub_days days -> Date
Returns the date a signed number of days earlier.
Parameters
| Name | Type | Description |
|---|---|---|
days |
Int |
Days to subtract. May be negative. |
Errors
| Exception | Condition |
|---|---|
TypeError |
days is not an Int |
OverflowError |
The result is outside the supported range |