Timestamp structv0.1.0
pub struct Timestamp {
pub seconds: int64;
pub nanoseconds: uint32;
}
Copy. The value is seconds + nanoseconds / 1e9 from 1970-01-01T00:00:00 UTC, and nanoseconds is always in
[0, 1e9).
Fields
| Name | Type | Description |
|---|---|---|
seconds | int64 | Whole seconds since the epoch, carrying the sign. |
nanoseconds | uint32 | The fraction, in nanoseconds, always in [0, 1e9). |
Associated functions
Epoch
pub func Epoch() -> Timestamp
The epoch itself: 1970-01-01T00:00:00 UTC exactly.
Returns: 1970-01-01T00:00:00Z
Now
pub func Now() -> Timestamp
The wall clock, read now.
Returns: the wall clock, read now
FromUnixSeconds
pub func FromUnixSeconds(seconds: int64) -> Timestamp
A moment from a plain second count, the shape most protocols carry.
| Name | Type | Description |
|---|---|---|
seconds | int64 | how many seconds |
Returns: that many seconds after the epoch
Methods
UnixSeconds
pub func UnixSeconds(self: &Timestamp) -> int64
The whole seconds since the epoch, rounded toward negative infinity.
Returns: whole seconds since the epoch, negative before it
SubsecondNanoseconds
pub func SubsecondNanoseconds(self: &Timestamp) -> uint32
The fraction beyond the whole seconds, in nanoseconds.
Returns: the nanoseconds within the second, in [0, 999999999]
Since
pub func Since(
self: &Timestamp,
earlier: Timestamp
) -> Duration?
The span from earlier to this moment, or None past a duration's range.
May be negative: the wall clock jumps, and two readings taken across a clock-set really can come back
reversed. That is information, not an error, which is the difference from Instant::Since.
| Name | Type | Description |
|---|---|---|
earlier | Timestamp | the earlier reading |
Returns: the time between the two moments, or None when earlier is not earlier
Plus
pub func Plus(
self: &Timestamp,
span: Duration
) -> Timestamp?
This moment shifted by span, or None past the range.
| Name | Type | Description |
|---|---|---|
span | Duration | the duration |
Returns: the moment that far later, or None when it does not fit
Equals
pub func Equals(self: &Timestamp, other: Timestamp) -> bool
Whether two timestamps name the same moment.
| Name | Type | Description |
|---|---|---|
other | Timestamp | the value to compare against |
Returns: whether the two name the same moment
Compare
pub func Compare(
self: &Timestamp,
other: Timestamp
) -> Ordering
How this moment orders against other.
| Name | Type | Description |
|---|---|---|
other | Timestamp | the value to compare against |
Returns: how this moment orders against other
IsInCalendarRange
pub func IsInCalendarRange(self: &Timestamp) -> bool
Whether this moment falls inside the years the calendar spells, and so has an RFC 3339 text.
The bound is years 0000 through 9999, which is the range Date arithmetic already treats as the package's
own and the range RFC 3339's four year digits allow. A caller that must not meet a formatting failure asks
here first; one that renders through a placeholder learns the same thing as ValueOutOfRange.
Borrows the moment and leaves it untouched. Cannot fail; runs in constant time and allocates nothing.
Returns: true when the calendar form exists for this moment
Implements Display
Timestamp conforms to Display.
WriteDisplay
pub func WriteDisplay(
self: &Timestamp,
writer: &var TextWriter,
spec: FormatSpec
) -> ! FormatError
Writes the moment as RFC 3339 in UTC, or as the Unix second count under the unix style.
The calendar form is the default and the only one an unadorned placeholder produces: 1970-01-01T00:00:00Z
rather than 0. rfc3339 and iso8601 name that same form explicitly, and unix asks for the signed
second count instead — a value with two readings does not get to guess which one a caller meant.
A precision names exactly that many fractional digits, 0 through 9, and truncates, in either form. 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 the three named above or
for a precision past nine, and ValueOutOfRange for a moment outside years 0000 through 9999, which RFC
3339's four year digits cannot spell. The range is checked before anything is written, so a refused moment
leaves the destination as it was.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole moment was accepted
Implements Debug
Timestamp conforms to Debug.
WriteDebug
pub func WriteDebug(
self: &Timestamp,
writer: &var TextWriter,
spec: FormatSpec
) -> ! FormatError
The same text as Display: a moment has one reading, and the style chooses between the two forms here too.
The failures WriteDisplay reports, including ValueOutOfRange before any output.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole moment was accepted