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
sourceimpl Timestamp
impl Timestamp
sourcepub fn new(seconds: i64, nanos: u32) -> Timestamp
pub fn new(seconds: i64, nanos: u32) -> Timestamp
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 fn seconds(&self) -> i64
pub fn seconds(&self) -> i64
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);
sourcepub fn at_precision(&self, e: u8) -> i128
pub 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
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);
sourcepub fn subsec(&self, e: u8) -> u32
pub 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
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
sourceimpl AddAssign<Duration> for Timestamp
impl AddAssign<Duration> for Timestamp
sourcefn add_assign(&mut self, other: Duration)
fn add_assign(&mut self, other: Duration)
Add the provided duration to the timestamp, in-place.
sourceimpl<T: Into<i64> + Int> AddAssign<T> for Timestamp
impl<T: Into<i64> + Int> AddAssign<T> for Timestamp
sourcefn add_assign(&mut self, other: T)
fn add_assign(&mut self, other: T)
Add the provided duration to the timestamp, in-place.
sourceimpl Ord for Timestamp
impl Ord for Timestamp
sourceimpl PartialOrd<Timestamp> for Timestamp
impl PartialOrd<Timestamp> for Timestamp
sourcefn partial_cmp(&self, other: &Timestamp) -> Option<Ordering>
fn partial_cmp(&self, other: &Timestamp) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl SubAssign<Duration> for Timestamp
impl SubAssign<Duration> for Timestamp
sourcefn sub_assign(&mut self, other: Duration)
fn sub_assign(&mut self, other: Duration)
Subtract the provided duration to the timestamp, in-place.
sourceimpl<T: Into<i64> + Int> SubAssign<T> for Timestamp
impl<T: Into<i64> + Int> SubAssign<T> for Timestamp
sourcefn sub_assign(&mut self, other: T)
fn sub_assign(&mut self, other: T)
Subtract the provided duration to the timestamp, in-place.
impl Copy for Timestamp
impl Eq for Timestamp
impl StructuralEq for Timestamp
impl StructuralPartialEq for Timestamp
Auto Trait Implementations
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnwindSafe for Timestamp
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more