OffsetDateTime structv0.1.0

Source
A date and time together with the offset from UTC they are stated in.
pub struct OffsetDateTime {
    pub dateTime: DateTime;
    pub offset: UtcOffset;
}

DateTime deliberately carries no offset, since what offset a bare date and time is in is usually the caller's knowledge rather than the value's. This is the pairing for when it is not: an instant written down for interchange, where the offset is part of what was recorded and losing it changes the meaning. Copy, and exactly as wide as its two halves.

Fields

NameTypeDescription
dateTimeDateTimeThe local date and time, as stated in offset.
offsetUtcOffsetThe offset from UTC that dateTime is stated in.

Constructors

OffsetDateTime

pub func OffsetDateTime(
    dateTime: DateTime,
    offset: UtcOffset
) -> OffsetDateTime

The local date and time dateTime paired with the offset it is stated in. Cannot fail: both halves are already valid, and no combination of a valid date-time and a valid offset is invalid. Runs in constant time and allocates nothing.

NameTypeDescription
dateTimeDateTimethe local date and time
offsetUtcOffsetthe offset from UTC that dateTime is stated in

Returns: the pairing

Source

Methods

ToTimestamp

pub func ToTimestamp(self: &OffsetDateTime) -> Timestamp

The moment this names in UTC. Cannot fail; runs in constant time and allocates nothing.

Returns: the instant, as a timestamp

Source

Implements Display

OffsetDateTime conforms to Display.

WriteDisplay

pub func WriteDisplay(
    self: &OffsetDateTime,
    writer: &var TextWriter,
    spec: FormatSpec
) -> ! FormatError

Writes the moment as RFC 3339: YYYY-MM-DDTHH:MM:SS[.fraction] followed by Z or a signed HH:MM. This is the type that can produce RFC 3339, because it is the one that carries an offset. The offset is written as it is held rather than normalized to UTC: what was recorded includes where, and shifting it away would discard that. Reports whatever the writer reported, UnsupportedRequest for a style other than iso8601 or rfc3339, and UnsupportedRequest for a precision past nine.

NameTypeDescription
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for

Returns: success when the whole moment was accepted

Source

Implements Debug

OffsetDateTime conforms to Debug.

WriteDebug

pub func WriteDebug(
    self: &OffsetDateTime,
    writer: &var TextWriter,
    spec: FormatSpec
) -> ! FormatError

The same text as Display. The failures WriteDisplay reports.

NameTypeDescription
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for

Returns: success when the whole moment was accepted

Source

ParseRfc3339

pub func ParseRfc3339(text: char8[..]) -> OffsetDateTime ! TimeParseError

Reads YYYY-MM-DDTHH:MM:SS[.fraction](Z|+HH:MM|-HH:MM). The offset is required, which is what RFC 3339 requires and what makes the result a moment rather than a local reading. Second 60 folds to the last nanosecond of second 59, as this package's leap-second policy states; formatting never produces second 60, so the fold is one-way and the round trip is clean for every ordinary moment. The failures the date, time and offset readers report, plus InvalidSyntax for text after the offset. Each carries the byte offset where it was found.

Source

Parameters

NameTypeDescription
textchar8[..]the text to read

Returns: the moment with the offset it was stated in, or why the text is not one