Wado

core:temporal

Date and time, a port of ECMA-262 Temporal under the ISO 8601 calendar.

Two types carry an instant — Instant, an exact point on the timeline, and ZonedDateTime, that instant paired with the zone it is read in. Five are zoneless readings the way a birthday or a recurring wall-clock time is: PlainDate, PlainTime, PlainDateTime, PlainYearMonth, and PlainMonthDay. Duration is a signed span, and Unit and RoundingMode parameterize the difference and rounding operations.

Every type parses Temporal's RFC 9557 / ISO 8601 grammar and renders Temporal's toString, and that string is its serde wire form. Instant also reads and writes the RFC 7231 IMF-fixdate an HTTP Date header carries. Instant::now takes the system clock through the effect row, so a program that never asks the time gains no WASI import.

Where this module departs from the specification, it does so deliberately:

Relationship to wasi:clocks: wasi:clocks exposes its own Instant record ({ seconds, nanoseconds }) for the system clock. That type is a Component Model binding — pinned to a specific WASI version and regenerated by wado-from-idl — whereas core:temporal's Instant is a plain, version-independent Wado type that grows methods. They share a name and field layout deliberately: it is "the same concept, a different type", and From impls both ways bridge them with a field-for-field copy.

Every type here is ISO 8601 only and so stores no calendar.

Synopsis

let epoch = Instant::from_epoch_seconds(0);
assert `${epoch}` == "1970-01-01T00:00:00Z";
assert epoch < Instant::from_epoch_seconds(1_000_000_000);

let zoned = ZonedDateTime::from_str("2023-11-14T22:13:20+09:00[+09:00]").unwrap();
assert zoned.hour() == 22;
assert `${zoned}` == "2023-11-14T22:13:20+09:00[+09:00]";

// A duration reads as written, and a calendar unit needs a calendar to
// resolve it: 01-31 plus a month is 02-28, not 03-03.
let month = Duration { months: 1 };
assert `${month}` == "P1M";
assert PlainDate::new(2023, 1, 31).add(&month) == PlainDate::new(2023, 2, 28);

// The zoneless types are the shapes a date or a clock reading really has.
assert PlainDate::new(2024, 2, 29).in_leap_year();
assert `${PlainTime { hour: 9, minute: 30 }}` == "09:30:00";

// Every type reads its own spelling back through `FromStr`.
assert PlainDate::from_str("2024-02-29") matches { Ok(d) && d.in_leap_year() };
assert PlainYearMonth::from_str("2024-13") matches { Err(_) };

assert Instant::EPOCH.to_http_date() == "Thu, 01 Jan 1970 00:00:00 GMT";

Structs

pub struct Instant

An exact point on the timeline, as the offset from the Unix epoch (1970-01-01T00:00:00Z). Time-zone- and calendar-independent.

Corresponds to Temporal.Instant and the wasi:clocks instant record. Where Temporal stores epochNanoseconds as a BigInt, this uses an i64 second count plus a u32 sub-second part — the exact shape of wasi:clocks instant. Temporal's range applies: 10^8 days either side of the epoch, -271821-04-20T00:00:00Z through +275760-09-13T00:00:00Z.

Ord is auto-derived and orders chronologically: seconds is compared first, then nanoseconds.

seconds: i64

Whole seconds since the Unix epoch. Negative values are before it.

nanoseconds: u32

Sub-second component, always in 0..<1_000_000_000. Incrementing nanoseconds always moves forward in time, even when seconds < 0 (e.g. one nanosecond before the epoch is Instant { seconds: -1, nanoseconds: 999_999_999 }). Use Instant::new to normalize an arbitrary count into this range.

pub const EPOCH: Instant

The Unix epoch itself, 1970-01-01T00:00:00Z.

pub fn new(seconds: i64, nanoseconds: i64) -> Instant

Construct an instant nanoseconds after seconds since the Unix epoch, normalizing so the stored sub-second part lands in 0..<1_000_000_000 even when nanoseconds is negative or >= 1_000_000_000. Traps outside Temporal's range.

pub fn from_epoch_seconds(seconds: i64) -> Instant

Construct an instant from whole seconds since the Unix epoch (CBOR tag 1 integer form).

pub fn from_epoch_milliseconds(milliseconds: i64) -> Instant

Construct an instant from milliseconds since the Unix epoch (Temporal.Instant.fromEpochMilliseconds).

pub fn from_epoch_microseconds(microseconds: i64) -> Instant

Construct an instant from microseconds since the Unix epoch. The inverse of epoch_microseconds.

pub fn from_epoch_nanoseconds(nanoseconds: i128) -> Instant

Construct an instant from nanoseconds since the Unix epoch (Temporal.Instant.fromEpochNanoseconds).

pub fn from_unix_seconds(seconds: f64) -> Instant

Construct an instant from fractional seconds since the Unix epoch (CBOR tag 1 floating-point form). The fraction is rounded to the nearest nanosecond; f64 precision limits sub-microsecond accuracy near the present. Traps on a value that is not finite or is outside the range.

pub fn now() -> Instant with SystemClock

The current reading of the system clock (Temporal.Now.instant), clamped to the range as HostSystemUTCEpochNanoseconds requires. The effect row is what keeps the clock off callers that never ask the time.

pub fn epoch_milliseconds(&self) -> i64

Milliseconds since the Unix epoch (Temporal.Instant.epochMilliseconds), floored.

pub fn epoch_microseconds(&self) -> i64

Microseconds since the Unix epoch, floored.

pub fn epoch_nanoseconds(&self) -> i128

Nanoseconds since the Unix epoch (Temporal.Instant.epochNanoseconds). Temporal uses a BigInt; an i128 holds the whole range exactly.

pub fn add(&self, duration: &Duration) -> Instant

Move forward by duration. Only the time components are admitted: a day and above has no fixed length without a calendar, so Temporal measures those against a ZonedDateTime instead.

pub fn subtract(&self, duration: &Duration) -> Instant

Move back by duration, under the same restriction as add.

pub fn until(&self, other: &Instant, largest_unit: Unit = Unit::Second) -> Duration

The span from this instant to other, positive when other is later. largest_unit must be a time unit; Temporal's default is the second.

pub fn since(&self, other: &Instant, largest_unit: Unit = Unit::Second) -> Duration

The span from other to this instant — until with the sign flipped.

pub fn round(&self, smallest_unit: Unit, increment: i64 = 1, mode: RoundingMode = RoundingMode::HalfExpand) -> Instant

Round to a multiple of increment units counted from the epoch, as if the count were positive: Trunc rounds toward the past like Floor. smallest_unit must be a time unit, and the step must divide the day.

pub fn to_iso8601(&self) -> String

Temporal's toString (and toJSON): the UTC reading with a Z, its fraction printed as far as the last non-zero digit. This is the serde wire form, and an RFC 3339 timestamp in the years 0..=9999.

pub fn to_http_date(&self) -> String

RFC 7231 IMF-fixdate, the form an HTTP Date, Expires, or Last-Modified header carries: "Sun, 06 Nov 1994 08:49:37 GMT". Always UTC, always whole seconds; traps outside the years 0..=9999.

pub fn parse_http_date<S: AsStrSlice>(text: S) -> Result<Instant, DeserializeError>

Parse an HTTP-date in any of the three forms RFC 7231 requires a recipient to accept: IMF-fixdate ("Sun, 06 Nov 1994 08:49:37 GMT"), the obsolete RFC 850 ("Sunday, 06-Nov-94 08:49:37 GMT", whose two-digit year pivots at 70), and asctime ("Sun Nov 6 08:49:37 1994"). The weekday must be a weekday name, but is not checked against the date.

pub fn to_zoned_date_time<S: AsStrSlice>(&self, time_zone: S) -> ZonedDateTime

Interpret this instant in a time zone, the zoned view of the same moment (Temporal.Instant.toZonedDateTimeISO). The zone is a time zone identifier or an ISO string that carries one, as Temporal reads it.

impl Display for Instant

fn fmt(&self, f: &mut Formatter)

impl FromStr for Instant

fn from_str<S: AsStrSlice>(s: S) -> Result<Instant, DeserializeError>

impl Serialize for Instant

fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), SerializeError>

impl Deserialize for Instant

fn deserialize<D: Deserializer>(d: &mut D) -> Result<Instant, DeserializeError>

impl From<ClockInstant> for Instant

fn from(value: ClockInstant) -> Instant

pub struct ZonedDateTime

An exact instant together with the time zone it is interpreted in.

Corresponds to Temporal.ZonedDateTime — the only "complete" temporal value (an instant plus a wall-clock interpretation). The calendar is always ISO 8601 and therefore not stored. The broken-down wall-clock fields (year, month, day, hour, …) are a function of instant + time_zone, computed on demand by accessors rather than stored state.

Ord is auto-derived and orders by instant first, then time_zone lexically, so it stays consistent with the derived Eq, which is Temporal's equals. Temporal's compare weighs only the instant, so for "the same moment, wherever it is read" compare to_instant() rather than the values.

instant: Instant

The exact instant.

time_zone: String

The time zone identifier, as Temporal canonicalizes it: "UTC" or a fixed offset such as "+09:00". An IANA name such as "America/New_York" is storable in a literal, but every operation traps on it until a time zone database is bundled.

pub fn new<S: AsStrSlice>(instant: Instant, time_zone: S) -> ZonedDateTime

Interpret instant in time_zone (new Temporal.ZonedDateTime). The zone must be a time zone identifier, which this canonicalizes: "utc" becomes "UTC", "-00:00" becomes "+00:00", and "+0930" becomes "+09:30". "Z" is a designator rather than a zone, and a named zone other than UTC needs a time zone database; both trap.

pub fn now<S: AsStrSlice>(time_zone: S) -> ZonedDateTime with SystemClock

The current time read in time_zone (Temporal.Now.zonedDateTimeISO), which is read as Instant::to_zoned_date_time reads it. The zone is the caller's: there is no system-zone lookup until the wasi:clocks timezone interface is wired up.

pub fn parse_rfc3339<S: AsStrSlice>(text: S) -> Result<ZonedDateTime, DeserializeError>

Parse an RFC 3339 timestamp such as "2023-11-14T22:13:20.5+09:00", keeping what it says about the zone: Z reads as "UTC", and a numeric offset as that fixed-offset zone, so it round-trips through to_rfc3339. The grammar is that of an instant string without annotations, which are RFC 9557's; FromStr reads those. An offset with seconds names no zone and is an error.

pub fn to_instant(&self) -> Instant

The exact instant, dropping the zone (Temporal.ZonedDateTime.toInstant).

pub fn epoch_milliseconds(&self) -> i64

Milliseconds since the Unix epoch, floored.

pub fn epoch_nanoseconds(&self) -> i128

Nanoseconds since the Unix epoch.

pub fn offset(&self) -> String

The zone's UTC offset at this instant, as ±HH:MM; "+00:00" for UTC.

pub fn offset_nanoseconds(&self) -> i64

The zone's UTC offset at this instant, in nanoseconds.

pub fn year(&self) -> i32

ISO year in the zone's local time. May be negative or beyond four digits.

pub fn month(&self) -> i32

Month of the year, 1..=12.

pub fn month_code(&self) -> String

Temporal month code, "M01" … "M12" under the ISO 8601 calendar.

pub fn day(&self) -> i32

Day of the month, 1..=31.

pub fn hour(&self) -> i32

Hour of the day, 0..=23.

pub fn minute(&self) -> i32

Minute of the hour, 0..=59.

pub fn second(&self) -> i32

Second of the minute, 0..=59.

pub fn millisecond(&self) -> i32

Millisecond of the second, 0..=999.

pub fn microsecond(&self) -> i32

Microsecond of the millisecond, 0..=999.

pub fn nanosecond(&self) -> i32

Nanosecond of the microsecond, 0..=999.

pub fn day_of_week(&self) -> i32

Day of the week, 1 (Monday) through 7 (Sunday), per ISO 8601.

pub fn day_of_year(&self) -> i32

Day of the year, 1..=366.

pub fn week_of_year(&self) -> i32

ISO 8601 week of the week-year, 1..=53.

pub fn year_of_week(&self) -> i32

ISO 8601 week-numbering year, which differs from year in the days at either end of the year that belong to the neighbour's week.

pub fn days_in_week(&self) -> i32

Number of days in this week — always 7 for ISO 8601.

pub fn days_in_month(&self) -> i32

Number of days in this month, 28..=31.

pub fn days_in_year(&self) -> i32

Number of days in this year, 365 or 366.

pub fn months_in_year(&self) -> i32

Number of months in this year — always 12 for ISO 8601.

pub fn in_leap_year(&self) -> bool

Whether this year is a leap year in the ISO 8601 calendar.

pub fn hours_in_day(&self) -> i32

Hours between this day's start and the next. A fixed offset has no DST, so it is always 24; traps where either start is outside the range.

pub fn start_of_day(&self) -> ZonedDateTime

The first instant of this value's local day (startOfDay).

pub fn add(&self, duration: &Duration) -> ZonedDateTime

Move forward by duration (Temporal's AddZonedDateTime): the date components in local calendar days, a month-end overflow constrained to the month's last day, then the time components in exact time.

pub fn subtract(&self, duration: &Duration) -> ZonedDateTime

Move back by duration. Not the inverse of add when a month-end is constrained on the way out: 01-31 plus a month is 02-28, and minus a month again is 01-28.

pub fn until(&self, other: &ZonedDateTime, largest_unit: Unit = Unit::Hour) -> Duration

The span from this value to other, positive when other is later. A time largest_unit divides the exact span; a date one walks the local calendar, which needs both values in one zone. Temporal's default is the hour.

pub fn since(&self, other: &ZonedDateTime, largest_unit: Unit = Unit::Hour) -> Duration

The span from other to this value — until with the sign flipped.

pub fn round(&self, smallest_unit: Unit, increment: i64 = 1, mode: RoundingMode = RoundingMode::HalfExpand) -> ZonedDateTime

Round the local wall clock to a multiple of increment units, measured within the next larger unit as Temporal's RoundTime does. Unit::Day rounds to the nearest start of day and takes no increment but 1.

pub fn with_time_zone<S: AsStrSlice>(&self, time_zone: S) -> ZonedDateTime

The same instant read in another zone (withTimeZone), which is read as Instant::to_zoned_date_time reads it.

pub fn to_iso8601(&self) -> String

Temporal's toString (and toJSON): the local date and time, the offset, and the zone annotation, as in "2023-11-15T07:13:20+09:00[+09:00]". This is the serde wire form.

pub fn to_rfc3339(&self) -> String

The local date and time and the offset, without the zone annotation RFC 9557 adds: RFC 3339 in the years 0..=9999, and ISO 8601's expanded year outside them. parse_rfc3339 reads it back.

pub fn to_plain_date(&self) -> PlainDate

The local calendar date.

pub fn to_plain_time(&self) -> PlainTime

The local wall-clock time.

pub fn to_plain_date_time(&self) -> PlainDateTime

The local date and time together, dropping the zone.

impl Display for ZonedDateTime

fn fmt(&self, f: &mut Formatter)

impl FromStr for ZonedDateTime

fn from_str<S: AsStrSlice>(s: S) -> Result<ZonedDateTime, DeserializeError>

impl Serialize for ZonedDateTime

fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), SerializeError>

impl Deserialize for ZonedDateTime

fn deserialize<D: Deserializer>(d: &mut D) -> Result<ZonedDateTime, DeserializeError>

pub struct Duration

A signed span of time, as a Temporal-shaped record of ten components rather than one scalar. Corresponds to Temporal.Duration.

Each component is an f64 holding an integer, as Temporal's float64 does, so a result Temporal rounds to a float is rounded the same way here. A component may exceed 2^53, the integers an f64 holds exactly: a nanosecond count balanced from a span longer than about 104 days does.

Temporal's invariants hold: every component is a finite integer, every non-zero one has one sign, a year, month, or week count is below 2^32, and the days and time components together are below 2^53 seconds. A struct literal can break them, so every operation checks its receiver and traps on one that does. The date components (years, months, weeks) have no fixed length, so a duration carrying one applies only to a receiver that knows a calendar position.

years: f64

months: f64

weeks: f64

days: f64

hours: f64

minutes: f64

seconds: f64

milliseconds: f64

microseconds: f64

nanoseconds: f64

pub fn parse<S: AsStrSlice>(text: S) -> Result<Duration, DeserializeError>

Parse Temporal's ISO 8601 duration, such as "P1Y2M3W4DT5H6M7.5S", optionally signed. A fraction of up to nine digits is allowed on the last time component and spills into the components below it, so "PT1.5H" is PT1H30M. A result that is not a valid duration is an error.

pub fn sign(&self) -> i32

The sign of the duration: 1, -1, or 0 when every component is zero.

pub fn is_zero(&self) -> bool

Whether every component is zero (Temporal.Duration.prototype.blank).

pub fn negated(&self) -> Duration

The same span in the opposite direction.

pub fn abs(&self) -> Duration

The same span with a non-negative sign.

pub fn add(&self, other: &Duration) -> Duration

The two spans summed (Temporal's AddDurations), a day counting 24 hours, and balanced up to the larger of their largest units. Years, months, and weeks trap, since adding one needs the calendar position Temporal's relativeTo supplies.

pub fn subtract(&self, other: &Duration) -> Duration

The difference of the two spans, balanced the same way as add.

pub fn total(&self, unit: Unit) -> f64

The whole span expressed in unit, a day counting 24 hours, as the float nearest the exact quotient. Years, months, and weeks have no length without a calendar anchor, as a component or as the unit, and trap.

pub fn round(&self, smallest_unit: Unit, largest_unit: Unit, increment: i64 = 1, mode: RoundingMode = RoundingMode::HalfExpand) -> Duration

Round to a multiple of increment smallest_units, a day counting 24 hours, and balance up to largest_unit, which may be no smaller. Years, months, and weeks trap, as a component or as a unit. A time unit takes an increment that divides the next unit; a day takes any.

pub fn to_iso8601(&self) -> String

Temporal's toString (and toJSON), e.g. "P1Y2M3W4DT5H6M7.5S". A zero duration is "PT0S"; a negative one takes a leading -.

impl Display for Duration

fn fmt(&self, f: &mut Formatter)

impl Serialize for Duration

fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), SerializeError>

impl FromStr for Duration

fn from_str<S: AsStrSlice>(s: S) -> Result<Duration, DeserializeError>

impl Deserialize for Duration

fn deserialize<D: Deserializer>(d: &mut D) -> Result<Duration, DeserializeError>

pub struct PlainDate

A calendar date with no time and no zone. Corresponds to Temporal.PlainDate, over Temporal's range: -271821-04-19 through +275760-09-13. Ord is auto-derived over year, month, day and so orders chronologically.

year: i32

month: i32

day: i32

pub fn new(year: i32, month: i32, day: i32) -> PlainDate

A date, which must exist in the ISO 8601 calendar and be in range; it traps otherwise. Use constrain to clamp a day past the month's end instead, or from_str for input that may be malformed.

pub fn constrain(year: i32, month: i32, day: i32) -> PlainDate

A date with month clamped to 1..=12 and day to that month's length — Temporal's constrain overflow. Traps outside the range.

pub fn from_epoch_days(days: i64) -> PlainDate

The date days after the Unix epoch. Traps outside the range.

pub fn epoch_days(&self) -> i64

Days since 1970-01-01, negative before it.

pub fn day_of_week(&self) -> i32

Day of the week, 1 (Monday) through 7 (Sunday), per ISO 8601.

pub fn day_of_year(&self) -> i32

Day of the year, 1..=366.

pub fn week_of_year(&self) -> i32

ISO 8601 week of the week-year, 1..=53.

pub fn year_of_week(&self) -> i32

ISO 8601 week-numbering year, which differs from year in the days at either end of the year that belong to the neighbour's week.

pub fn days_in_week(&self) -> i32

Number of days in this week — always 7 for ISO 8601.

pub fn days_in_month(&self) -> i32

Number of days in this month, 28..=31.

pub fn days_in_year(&self) -> i32

Number of days in this year, 365 or 366.

pub fn months_in_year(&self) -> i32

Number of months in this year — always 12 for ISO 8601.

pub fn in_leap_year(&self) -> bool

Whether this year is a leap year in the ISO 8601 calendar.

pub fn month_code(&self) -> String

Temporal month code, "M01" … "M12".

pub fn add(&self, duration: &Duration) -> PlainDate

Move forward by duration (Temporal's AddDurationToDate): the time components fold into whole days, truncated, and a month-end overflow is constrained to the month's last day. Traps outside the range.

pub fn subtract(&self, duration: &Duration) -> PlainDate

Move back by duration. Not the inverse of add when a month-end is constrained on the way out.

pub fn until(&self, other: &PlainDate, largest_unit: Unit = Unit::Day) -> Duration

The span from this date to other, positive when other is later. largest_unit must be a date unit; Temporal's default is the day.

pub fn since(&self, other: &PlainDate, largest_unit: Unit = Unit::Day) -> Duration

The span from other to this date — until with the sign flipped.

pub fn to_plain_year_month(&self) -> PlainYearMonth

Drop the day.

pub fn to_plain_month_day(&self) -> PlainMonthDay

Drop the year.

pub fn to_plain_date_time(&self, time: PlainTime = PlainTime {}) -> PlainDateTime

Pair this date with a wall-clock time.

pub fn to_zoned_date_time<S: AsStrSlice>(&self, time_zone: S, time: PlainTime = PlainTime {}) -> ZonedDateTime

Read this date at time in time_zone, which resolves it to an instant. The zone is read as Instant::to_zoned_date_time reads it.

pub fn to_iso8601(&self) -> String

Temporal's toString: YYYY-MM-DD, with a sign and six digits where the year does not fit four.

impl Display for PlainDate

fn fmt(&self, f: &mut Formatter)

impl FromStr for PlainDate

fn from_str<S: AsStrSlice>(s: S) -> Result<PlainDate, DeserializeError>

impl Serialize for PlainDate

fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), SerializeError>

impl Deserialize for PlainDate

fn deserialize<D: Deserializer>(d: &mut D) -> Result<PlainDate, DeserializeError>

pub struct PlainTime

A wall-clock time with no date and no zone. Corresponds to Temporal.PlainTime. Ord is auto-derived over the components in descending significance and so orders chronologically within a day.

hour: i32

minute: i32

second: i32

millisecond: i32

microsecond: i32

nanosecond: i32

pub fn new(hour: i32, minute: i32, second: i32 = 0, millisecond: i32 = 0, microsecond: i32 = 0, nanosecond: i32 = 0) -> PlainTime

A wall-clock time, which traps out of range. Every component defaults to zero, so PlainTime { hour: 9 } is 09:00:00.

pub fn is_valid(&self) -> bool

Whether every component is in the range the ISO 8601 clock allows.

pub fn nanoseconds_since_midnight(&self) -> i64

Nanoseconds since midnight, 0..<86_400_000_000_000.

pub fn from_nanoseconds_since_midnight(nanoseconds: i64) -> PlainTime

The time nanoseconds after midnight, wrapping into 0..<24h so a negative or overflowing count lands on the same clock reading a day's worth of turning would.

pub fn add(&self, duration: &Duration) -> PlainTime

Move forward by duration's time components, wrapping around midnight (Temporal's AddDurationToTime). The date components, days included, do not move a clock.

pub fn subtract(&self, duration: &Duration) -> PlainTime

Move back by duration, wrapping the same way.

pub fn until(&self, other: &PlainTime, largest_unit: Unit = Unit::Hour) -> Duration

The span from this time to other within one day, positive when other is later on the clock. largest_unit must be a time unit; Temporal's default is the hour.

pub fn since(&self, other: &PlainTime, largest_unit: Unit = Unit::Hour) -> Duration

The span from other to this time — until with the sign flipped.

pub fn round(&self, smallest_unit: Unit, increment: i64 = 1, mode: RoundingMode = RoundingMode::HalfExpand) -> PlainTime

Round to a multiple of increment units, measured within the next larger unit as Temporal's RoundTime does, and wrapping at the end of the day. The increment must divide the next unit.

pub fn to_iso8601(&self) -> String

Temporal's toString: hh:mm:ss, and the fraction as far as its last non-zero digit.

impl Display for PlainTime

fn fmt(&self, f: &mut Formatter)

impl FromStr for PlainTime

fn from_str<S: AsStrSlice>(s: S) -> Result<PlainTime, DeserializeError>

impl Serialize for PlainTime

fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), SerializeError>

impl Deserialize for PlainTime

fn deserialize<D: Deserializer>(d: &mut D) -> Result<PlainTime, DeserializeError>

pub struct PlainDateTime

A date and a wall-clock time with no zone, and so no instant — the pair still names a different moment in every zone. Corresponds to Temporal.PlainDateTime, over the instant range widened by a day either side, exclusive.

date: PlainDate

time: PlainTime

pub fn new(date: PlainDate, time: PlainTime = PlainTime {}) -> PlainDateTime

A date and time, which traps out of range.

pub fn add(&self, duration: &Duration) -> PlainDateTime

Move forward by duration (Temporal's AddDurationToDateTime): the days and time in exact time, carrying whole days into the date, then the years, months, and weeks with a month-end overflow constrained.

pub fn subtract(&self, duration: &Duration) -> PlainDateTime

Move back by duration.

pub fn until(&self, other: &PlainDateTime, largest_unit: Unit = Unit::Day) -> Duration

The span from this value to other, positive when other is later (Temporal's DifferenceISODateTime). Temporal's default largest unit is the day.

pub fn since(&self, other: &PlainDateTime, largest_unit: Unit = Unit::Day) -> Duration

The span from other to this value — until with the sign flipped.

pub fn round(&self, smallest_unit: Unit, increment: i64 = 1, mode: RoundingMode = RoundingMode::HalfExpand) -> PlainDateTime

Round the clock to a multiple of increment units, measured within the next larger unit as Temporal's RoundTime does, carrying into the date. Unit::Day rounds to the nearest midnight and takes no increment but 1.

pub fn to_zoned_date_time<S: AsStrSlice>(&self, time_zone: S) -> ZonedDateTime

Read this reading in time_zone, which resolves it to an instant. The zone is read as Instant::to_zoned_date_time reads it.

pub fn to_iso8601(&self) -> String

Temporal's toString: YYYY-MM-DDThh:mm:ss, and the fraction as far as its last non-zero digit.

impl Display for PlainDateTime

fn fmt(&self, f: &mut Formatter)

impl FromStr for PlainDateTime

fn from_str<S: AsStrSlice>(s: S) -> Result<PlainDateTime, DeserializeError>

impl Serialize for PlainDateTime

fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), SerializeError>

impl Deserialize for PlainDateTime

fn deserialize<D: Deserializer>(d: &mut D) -> Result<PlainDateTime, DeserializeError>

pub struct PlainYearMonth

A month of a particular year, with no day — a credit-card expiry, a billing period. Corresponds to Temporal.PlainYearMonth, over -271821-04 through +275760-09.

year: i32

month: i32

pub fn new(year: i32, month: i32) -> PlainYearMonth

A year and month, which traps out of range.

pub fn days_in_month(&self) -> i32

Number of days in this month, 28..=31.

pub fn days_in_year(&self) -> i32

Number of days in this year, 365 or 366.

pub fn months_in_year(&self) -> i32

Number of months in this year — always 12 for ISO 8601.

pub fn in_leap_year(&self) -> bool

Whether this year is a leap year in the ISO 8601 calendar.

pub fn month_code(&self) -> String

Temporal month code, "M01" … "M12".

pub fn add(&self, duration: &Duration) -> PlainYearMonth

Move forward by duration's years and months (Temporal's AddDurationToYearMonth), from the first of the month. Weeks, days, and time trap, as does a first of the month outside the date range.

pub fn subtract(&self, duration: &Duration) -> PlainYearMonth

Move back by duration.

pub fn until(&self, other: &PlainYearMonth, largest_unit: Unit = Unit::Year) -> Duration

The span from this month to other, positive when other is later. largest_unit is Year, Temporal's default, or Month.

pub fn since(&self, other: &PlainYearMonth, largest_unit: Unit = Unit::Year) -> Duration

The span from other to this month — until with the sign flipped.

pub fn to_plain_date(&self, day: i32) -> PlainDate

Land this month on a day, clamped to the month's length. Traps outside the date range.

pub fn to_iso8601(&self) -> String

Temporal's toString: YYYY-MM.

impl Display for PlainYearMonth

fn fmt(&self, f: &mut Formatter)

impl FromStr for PlainYearMonth

fn from_str<S: AsStrSlice>(s: S) -> Result<PlainYearMonth, DeserializeError>

impl Serialize for PlainYearMonth

fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), SerializeError>

impl Deserialize for PlainYearMonth

fn deserialize<D: Deserializer>(d: &mut D) -> Result<PlainYearMonth, DeserializeError>

pub struct PlainMonthDay

A day of a month with no year — a birthday, an anniversary. Corresponds to Temporal.PlainMonthDay. February 29 is representable; landing it on a year is to_plain_date's problem.

month: i32

day: i32

pub fn new(month: i32, day: i32) -> PlainMonthDay

A month and day, which must exist in some year — February 29 does, so it is accepted here and resolved by to_plain_date.

pub fn to_plain_date(&self, year: i32) -> PlainDate

Land this month-day in year, clamping February 29 to the 28th outside a leap year. Traps outside the date range.

pub fn month_code(&self) -> String

Temporal month code, "M01" … "M12".

pub fn to_iso8601(&self) -> String

Temporal's toString under ISO 8601: MM-DD.

impl Display for PlainMonthDay

fn fmt(&self, f: &mut Formatter)

impl FromStr for PlainMonthDay

fn from_str<S: AsStrSlice>(s: S) -> Result<PlainMonthDay, DeserializeError>

impl Serialize for PlainMonthDay

fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), SerializeError>

impl Deserialize for PlainMonthDay

fn deserialize<D: Deserializer>(d: &mut D) -> Result<PlainMonthDay, DeserializeError>

Enums

pub enum Unit

The unit a temporal difference or rounding operation works in. The order is Temporal's, largest first; Year, Month, Week, and Day are the date units, the rest the time units.

Year

Month

Week

Day

Hour

Minute

Second

Millisecond

Microsecond

Nanosecond

pub enum RoundingMode

How a rounding operation breaks a tie and which way it moves. Temporal's nine modes: the first four are directed, the Half* five choose only when the value sits exactly halfway.

Ceil

Toward positive infinity.

Floor

Toward negative infinity.

Expand

Away from zero.

Trunc

Toward zero.

HalfCeil

Nearest; a tie goes toward positive infinity.

HalfFloor

Nearest; a tie goes toward negative infinity.

HalfExpand

Nearest; a tie goes away from zero. Temporal's default.

HalfTrunc

Nearest; a tie goes toward zero.

HalfEven

Nearest; a tie goes to the even multiple.