Struct unix_ts::Timestamp [−][src]
pub struct Timestamp { /* fields omitted */ }
Expand description
A representation of a timestamp (seconds and nanos since the Unix epoch).
Timestamps are able to be easily converted into chrono DateTimes.
Implementations
Create a new timestamp from the given number of seconds
and nanos
(nanoseconds).
The use of the ts!()
macro in the unix-ts-macros
crate is advised
in lieu of calling this method directly for most situations.
Note: For negative timestamps, the nanos
argument is always a
positive offset. Therefore, the correct way to represent a timestamp
of -0.25 seconds
is to call new(-1, 750_000_000)
.
Return the seconds since the Unix epoch. Sub-second values are discarded.
Examples
use unix_ts::Timestamp;
let t = Timestamp::from(1335020400);
assert_eq!(t.seconds(), 1335020400);
Return the time since the Unix epoch, as an integer, with the given precision.
Arguments
e
(u8
) - The precision for the returned integer, as a power of 10. (ex. 3 for milliseconds, 6 for microseconds, etc.). Must be a value between 0 and 9.
Examples
use unix_ts::Timestamp;
let t = Timestamp::from(1335020400);
assert_eq!(t.at_precision(3), 1335020400_000);
assert_eq!(t.at_precision(6), 1335020400_000_000);
Return the subsecond component at the specified precision (ex. 3 for milliseconds, 6 for microseconds); max precision is 9.
Arguments
e
(u8
) - The precision for the returned subsecond value, as a power of 10 (ex. 3 for milliseconds, 6 for microseconds, etc.). Must be a value between 0 and 9.
Examples
use unix_ts::Timestamp;
let t = Timestamp::new(1335020400, 500_000_000);
assert_eq!(t.subsec(1), 5);
assert_eq!(t.subsec(3), 500);
Trait Implementations
Add the provided duration to the timestamp, in-place.
Add the provided duration to the timestamp, in-place.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Subtract the provided duration to the timestamp, in-place.
Subtract the provided duration to the timestamp, in-place.
Auto Trait Implementations
impl RefUnwindSafe for Timestamp
impl UnwindSafe for Timestamp
Blanket Implementations
Mutably borrows from an owned value. Read more