DateTime structv0.1.0
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
| Name | Type | Description |
|---|---|---|
date | Date | The day. |
time | TimeOfDay | The time within it. |
Associated functions
FromTimestamp
pub func FromTimestamp(
moment: Timestamp,
offset: UtcOffset
) -> DateTime
The date and time moment names, shifted into offset.
| Name | Type | Description |
|---|---|---|
moment | Timestamp | the moment to convert |
offset | UtcOffset | the offset from UTC |
Returns: the local date and time that moment names at that offset
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.
| Name | Type | Description |
|---|---|---|
offset | UtcOffset | the offset from UTC |
Returns: the moment this local time names at that offset
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.
| Name | Type | Description |
|---|---|---|
other | DateTime | the value to compare against |
Returns: whether the two are the same
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.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole date and time were accepted
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.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole date and time were accepted
Related
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.
Parameters
| Name | Type | Description |
|---|---|---|
text | char8[..] | the text to read |
Returns: the local date and time, or why the text is not one