table::date
On this page
Calendar dates and timestamps in the proleptic Gregorian calendar,
UTC, with no leap seconds. Day arithmetic follows Howard Hinnant's
days_from_civil / civil_from_days, exact over the whole range.
Structs
DateSource
pub struct DateA calendar date: days since 1970-01-01 (negative before it).
let d = table::Date::ymd(2024, 2, 29) ?? table::Date::from_days(0);
assert(f"{d}" == "2024-02-29");
assert(d.weekday() == 3); // Thursday, Monday is 0
The date
daysafter 1970-01-01.nabiassert(f"{table::Date::from_days(19723)}" == "2024-01-01");year-month-day, ornonewhen there is no such day.nabiassert(table::Date::ymd(2023, 2, 29) is none);An ISO 8601 date,
YYYY-MM-DD;nonefor anything else.nabiassert(table::Date::parse("2024-13-01") is none);Days since 1970-01-01.
(year, month, day).nabilet d = table::Date::from_days(0); assert(d.parts() == (1970, 1u32, 1u32));The year (proleptic Gregorian, year 0 is 1 BC).
The month, 1 to 12.
The day of the month, 1 to 31.
Day of the week, Monday 0 to Sunday 6.
ndays later (earlier for a negativen).nabiassert(f"{table::Date::from_days(0).add_days(-1)}" == "1969-12-31");Midnight UTC of this day.
Trait implementations 2
impl Display for Dateimpl Debug for Date
DateTimeSource
pub struct DateTimeAn instant: nanoseconds since 1970-01-01T00:00:00Z, which covers the years 1677 to 2262.
let t = table::DateTime::parse("2024-01-15T10:30:00Z") ?? table::DateTime::from_ns(0);
assert(t.date() == (table::Date::ymd(2024, 1, 15) ?? table::Date::from_days(0)));
assert(f"{t}" == "2024-01-15T10:30:00");
nsnanoseconds after 1970-01-01T00:00:00Z.Whole seconds after the epoch.
A
std::time::SystemTime, to the nanosecond.ISO 8601
YYYY-MM-DD, then optionallyTor a space andHH:MM,:SS, a fraction of up to 9 digits and a finalZ;nonefor anything else. A bare date is midnight.nabilet t = table::DateTime::parse("2024-01-15 10:30:00.25") ?? table::DateTime::from_ns(0); assert(t.ns() % 1000000000 == 250000000);Nanoseconds since the epoch.
The calendar day (UTC).
(hour, minute, second, nanosecond)within the day.dlater.The time from
earlierto this one.
Trait implementations 2
impl Display for DateTimeimpl Debug for DateTime
Functions
date_literalSource
pub const fn date_literal(s: str) -> Date date"2024-01-15": a Date, checked when the program compiles.
let d = date"2024-01-15";
assert(d.month() == 1u32);
datetime_literalSource
pub const fn datetime_literal(s: str) -> DateTime datetime"2024-01-15T10:30:00": a DateTime, checked when the
program compiles.
let t = datetime"2024-01-15T10:30:00";
assert(t.time().0 == 10u32);