TimeOfDay structv0.1.0
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
| Name | Type | Description |
|---|---|---|
hour | uint8 | The hour, 0 through 23. |
minute | uint8 | The minute, 0 through 59. |
second | uint8 | The second, 0 through 59. |
nanosecond | uint32 | The fraction, in nanoseconds. |
Associated functions
New
pub func New(
hour: uint8,
minute: uint8,
second: uint8,
nanosecond: uint32
) -> TimeOfDay?
The time, when it exists.
| Name | Type | Description |
|---|---|---|
hour | uint8 | the hour, 0 through 23 |
minute | uint8 | the minute, 0 through 59 |
second | uint8 | the second, 0 through 59 |
nanosecond | uint32 | the nanosecond within the second |
Returns: the time, or None when the components do not name one
Midnight
pub func Midnight() -> TimeOfDay
Midnight exactly.
Returns: the first instant of a day
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
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.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole time was accepted
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.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole time was accepted
Related
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.
Parameters
| Name | Type | Description |
|---|---|---|
text | char8[..] | the text to read |
Returns: the time of day, or why the text is not one