DateTime structv0.1.0

Source
A date and a time of day together, in some understood offset.
pub struct DateTime {
    pub date: Date;
    pub time: TimeOfDay;
}

Copy. What offset the pair is in is the caller's knowledge, carried beside it where it matters — attaching one permanently would make every arithmetic answer depend on a field that is usually UTC anyway.

Fields

NameTypeDescription
dateDateThe day.
timeTimeOfDayThe time within it.

Associated functions

FromTimestamp

pub func FromTimestamp(
    moment: Timestamp,
    offset: UtcOffset
) -> DateTime

The date and time moment names, shifted into offset.

NameTypeDescription
momentTimestampthe moment to convert
offsetUtcOffsetthe offset from UTC

Returns: the local date and time that moment names at that offset

Source

Methods

ToTimestamp

pub func ToTimestamp(
    self: &DateTime,
    offset: UtcOffset
) -> Timestamp

The moment this date and time name in UTC, shifted by offset. The shift subtracts: half past nine at plus two is half past seven in UTC. The range of a timestamp dwarfs the calendar's, so the conversion cannot overflow for any date Date::New accepts.

NameTypeDescription
offsetUtcOffsetthe offset from UTC

Returns: the moment this local time names at that offset

Source

Equals

pub func Equals(self: &DateTime, other: DateTime) -> bool

Whether two pairs name the same date and time. Same field values — two pairs in different offsets naming one moment are different here, which is what carrying the offset beside the pair means.

NameTypeDescription
otherDateTimethe value to compare against

Returns: whether the two are the same

Source

Implements Display

DateTime conforms to Display.

WriteDisplay

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

Writes the local date and time as YYYY-MM-DDTHH:MM:SS, with no offset. The absence is deliberate and is the point of the type. A DateTime holds no offset, so writing one would mean inventing it: Z would claim UTC and the machine's local offset would claim a place, and both would be a guess presented as a fact. OffsetDateTime is the type that has somewhere to keep an offset, and it is what produces RFC 3339. 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 date and time were accepted

Source

Implements Debug

DateTime conforms to Debug.

WriteDebug

pub func WriteDebug(
    self: &DateTime,
    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 date and time were accepted

Source

ParseDateTime

pub func ParseDateTime(text: char8[..]) -> DateTime ! TimeParseError

Reads YYYY-MM-DDTHH:MM:SS[.fraction], with no offset. The separator may be T, t or a space, which is as far as the RFC 3339 liberality goes. No offset is read, and one present is text after the value: a DateTime has nowhere to keep an offset, so accepting one would discard it silently. ParseRfc3339 is what reads a moment that carries one. The failures ParseDate and ParseTimeOfDay report, at their offsets within this text.

Source

Parameters

NameTypeDescription
textchar8[..]the text to read

Returns: the local date and time, or why the text is not one