pub struct Timestamp { /* private fields */ }
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§
Source§impl Timestamp
Creation of timestamps.
impl Timestamp
Creation of timestamps.
Sourcepub const fn new(seconds: i64, nanos: u32) -> Self
pub const fn new(seconds: i64, nanos: u32) -> Self
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)
.
Sourcepub const fn from_nanos(nanos: i128) -> Self
pub const fn from_nanos(nanos: i128) -> Self
Create a timestamp from the given number of nanoseconds.
Sourcepub const fn from_micros(micros: i64) -> Self
pub const fn from_micros(micros: i64) -> Self
Create a timestamp from the given number of microseconds.
Sourcepub const fn from_millis(millis: i64) -> Self
pub const fn from_millis(millis: i64) -> Self
Create a timestamp from the given number of milliseconds.
Source§impl Timestamp
Inspection of timestamps.
impl Timestamp
Inspection of timestamps.
Sourcepub const fn seconds(&self) -> i64
pub const fn seconds(&self) -> i64
Return the seconds since the Unix epoch. Sub-second values are discarded.
§Examples
let t = Timestamp::from(1335020400);
assert_eq!(t.seconds(), 1335020400);
Sourcepub const fn at_precision(&self, e: u8) -> i128
pub const fn at_precision(&self, e: u8) -> i128
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
let t = Timestamp::from(1335020400);
assert_eq!(t.at_precision(3), 1335020400_000);
assert_eq!(t.at_precision(6), 1335020400_000_000);
Sourcepub const fn subsec(&self, e: u8) -> u32
pub const fn subsec(&self, e: u8) -> u32
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
let t = Timestamp::new(1335020400, 500_000_000);
assert_eq!(t.subsec(1), 5);
assert_eq!(t.subsec(3), 500);
Trait Implementations§
Source§impl AddAssign<Duration> for Timestamp
impl AddAssign<Duration> for Timestamp
Source§fn add_assign(&mut self, other: Duration)
fn add_assign(&mut self, other: Duration)
Add the provided duration to the timestamp, in-place.
Source§impl<T: Into<i64> + Int> AddAssign<T> for Timestamp
impl<T: Into<i64> + Int> AddAssign<T> for Timestamp
Source§fn add_assign(&mut self, other: T)
fn add_assign(&mut self, other: T)
Add the provided duration to the timestamp, in-place.
Source§impl Ord for Timestamp
impl Ord for Timestamp
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§impl SubAssign<Duration> for Timestamp
impl SubAssign<Duration> for Timestamp
Source§fn sub_assign(&mut self, other: Duration)
fn sub_assign(&mut self, other: Duration)
Subtract the provided duration to the timestamp, in-place.
Source§impl<T: Into<i64> + Int> SubAssign<T> for Timestamp
impl<T: Into<i64> + Int> SubAssign<T> for Timestamp
Source§fn sub_assign(&mut self, other: T)
fn sub_assign(&mut self, other: T)
Subtract the provided duration to the timestamp, in-place.