Datetime¶
| Spice | |
|---|---|
DateTime struct¶
Calendar representation of a point in time in UTC. Fields use natural calendar values: month is 1-12 and day is 1-31.
Methods¶
print¶
| Spice | |
|---|---|
Print the DateTime to stdout in ISO 8601 style: YYYY-MM-DD HH:MM:SS. Note: No trailing newline is emitted.
Functions¶
of¶
| Spice | |
|---|---|
Construct a DateTime from its individual calendar components (UTC).
Parameters
| Name | Type | Description |
|---|---|---|
year |
int |
Year (e.g. 2026) |
month |
int |
Month in range [1, 12] |
day |
int |
Day of month in range [1, 31] |
hour |
int |
Hour in range [0, 23] |
minute |
int |
Minute in range [0, 59] |
second |
int |
Second in range [0, 59] |
Returns: DateTime — Constructed DateTime
ofDate¶
| Spice | |
|---|---|
Construct a DateTime at midnight (00:00:00) of the given date (UTC).
Parameters
| Name | Type | Description |
|---|---|---|
year |
int |
Year (e.g. 2026) |
month |
int |
Month in range [1, 12] |
day |
int |
Day of month in range [1, 31] |
Returns: DateTime — Constructed DateTime
fromUnixSecs¶
| Spice | |
|---|---|
Convert seconds since the Unix epoch (1970-01-01T00:00:00Z) into a calendar DateTime (UTC). Uses the well-known civil-from-days algorithm by Howard Hinnant.
Parameters
| Name | Type | Description |
|---|---|---|
secs |
long |
Seconds since the Unix epoch |
Returns: DateTime — Corresponding DateTime in UTC
toUnixSecs¶
| Spice | |
|---|---|
Convert a calendar DateTime (UTC) into seconds since the Unix epoch. Uses the well-known days-from-civil algorithm by Howard Hinnant.
Parameters
| Name | Type | Description |
|---|---|---|
dt |
const DateTime& |
Input DateTime (interpreted as UTC) |
Returns: long — Seconds since the Unix epoch
now¶
| Spice | |
|---|---|
Retrieve the current point in time as a DateTime in UTC.
Returns: DateTime — Current DateTime in UTC
daysInMonth¶
| Spice | |
|---|---|
Determine the number of days in the given month of the given year.
Parameters
| Name | Type | Description |
|---|---|---|
year |
int |
Year (used to account for leap years in February) |
month |
int |
Month in range [1, 12] |
Returns: int — Number of days in the month
dayOfWeek¶
| Spice | |
|---|---|
Determine the day of the week for the given DateTime. The result is in range [0, 6], where 0 = Sunday and 6 = Saturday.
Parameters
| Name | Type | Description |
|---|---|---|
dt |
const DateTime& |
Input DateTime |
Returns: int — Day of week in range [0, 6]
dayOfYear¶
| Spice | |
|---|---|
Determine the day of the year for the given DateTime. The result is in range [1, 366], where January 1st is day 1.
Parameters
| Name | Type | Description |
|---|---|---|
dt |
const DateTime& |
Input DateTime |
Returns: int — Day of year in range [1, 366]
addSeconds¶
| Spice | |
|---|---|
Return a copy of the DateTime advanced by the given number of seconds. A negative value moves the DateTime backwards in time.
Parameters
| Name | Type | Description |
|---|---|---|
dt |
const DateTime& |
Input DateTime |
seconds |
long |
Number of seconds to add |
Returns: DateTime — Resulting DateTime
addDays¶
| Spice | |
|---|---|
Return a copy of the DateTime advanced by the given number of days. A negative value moves the DateTime backwards in time.
Parameters
| Name | Type | Description |
|---|---|---|
dt |
const DateTime& |
Input DateTime |
days |
long |
Number of days to add |
Returns: DateTime — Resulting DateTime
isBefore¶
| Spice | |
|---|---|
Check whether the first DateTime lies strictly before the second.
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
const DateTime& |
First DateTime |
rhs |
const DateTime& |
Second DateTime |
Returns: bool — true if lhs is before rhs
isAfter¶
| Spice | |
|---|---|
Check whether the first DateTime lies strictly after the second.
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
const DateTime& |
First DateTime |
rhs |
const DateTime& |
Second DateTime |
Returns: bool — true if lhs is after rhs
equals¶
| Spice | |
|---|---|
Check whether two DateTimes represent the same point in time.
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
const DateTime& |
First DateTime |
rhs |
const DateTime& |
Second DateTime |
Returns: bool — true if both represent the same point in time