TimeOfDay structv0.1.0

Source
A time within a day, to the nanosecond.
pub struct TimeOfDay {
    pub hour: uint8;
    pub minute: uint8;
    pub second: uint8;
    pub nanosecond: uint32;
}

Copy, and only constructible valid. The second stops at 59: leap seconds are a policy for the text boundary, not a representable value here.

Fields

NameTypeDescription
houruint8The hour, 0 through 23.
minuteuint8The minute, 0 through 59.
seconduint8The second, 0 through 59.
nanoseconduint32The fraction, in nanoseconds.

Associated functions

New

pub func New(
    hour: uint8,
    minute: uint8,
    second: uint8,
    nanosecond: uint32
) -> TimeOfDay?

The time, when it exists.

NameTypeDescription
houruint8the hour, 0 through 23
minuteuint8the minute, 0 through 59
seconduint8the second, 0 through 59
nanoseconduint32the nanosecond within the second

Returns: the time, or None when the components do not name one

Source

Midnight

pub func Midnight() -> TimeOfDay

Midnight exactly.

Returns: the first instant of a day

Source

Methods

SecondsFromMidnight

pub func SecondsFromMidnight(self: &TimeOfDay) -> uint32

The seconds from midnight to this time, ignoring the fraction.

Returns: how many whole seconds into the day this is

Source

Implements Display

TimeOfDay conforms to Display.

WriteDisplay

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

Writes the time as HH:MM:SS, with a fractional part when there is one. A precision names exactly that many fractional digits, 0 through 9, and truncates. Without one the fraction is written to the digits it has with trailing zeros trimmed, and omitted when it is zero. Reports whatever the writer reported, UnsupportedRequest for a style other than iso8601 or rfc3339, and UnsupportedRequest for a precision past nine, which no fraction has.

NameTypeDescription
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for

Returns: success when the whole time was accepted

Source

Implements Debug

TimeOfDay conforms to Debug.

WriteDebug

pub func WriteDebug(
    self: &TimeOfDay,
    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 time was accepted

Source

ParseTimeOfDay

pub func ParseTimeOfDay(text: char8[..]) -> TimeOfDay ! TimeParseError

Reads HH:MM:SS with an optional fractional second. Reports InvalidSyntax for a shape that does not match, InvalidTime for a field outside its range, and ExcessiveFraction for more fraction digits than a nanosecond holds. Second 60 folds rather than failing.

Source

Parameters

NameTypeDescription
textchar8[..]the text to read

Returns: the time of day, or why the text is not one