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
ValueError if 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
DataError if the input is not a valid YYYY-MM-DD
date.
today() -> Date
Returns the current UTC date.
Fields
day @ Int[get]Day of month.
month @ Month[get]Calendar month.
weekday @ Weekday[get]Day of week.
year @ Int[get]Calendar year.
Methods
(eq) other -> Bool
Compares two dates.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Value |
(lt) other -> Bool
Orders two dates.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Date |
(str)() -> 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
OverflowError if 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
OverflowError if the result is outside the
supported range.