Struct humantime::Timestamp
[−]
[src]
pub struct Timestamp(_);
A wrapper for SystemTime that has FromStr
implementation
This is useful if you want to use it somewhere where FromStr
is
expected.
See parse_rfc3339_weak
for the description of the format. The "weak"
format is used as it's more pemissive for human input as this is the
expected use of the type (e.g. command-line parsing).
Example
use std::time::SystemTime; let x: SystemTime; x = "2018-02-16T00:31:37Z".parse::<humantime::Timestamp>().unwrap().into(); assert_eq!(humantime::format_rfc3339(x).to_string(), "2018-02-16T00:31:37Z");
Methods from Deref<Target = SystemTime>
pub const UNIX_EPOCH: SystemTime
pub fn duration_since(
&self,
earlier: SystemTime
) -> Result<Duration, SystemTimeError>
1.8.0[src]
pub fn duration_since(
&self,
earlier: SystemTime
) -> Result<Duration, SystemTimeError>
Returns the amount of time elapsed from an earlier point in time.
This function may fail because measurements taken earlier are not guaranteed to always be before later measurements (due to anomalies such as the system clock being adjusted either forwards or backwards).
If successful, Ok
(
Duration
)
is returned where the duration represents
the amount of time elapsed from the specified measurement to this one.
Returns an Err
if earlier
is later than self
, and the error
contains how far from self
the time is.
Examples
use std::time::SystemTime; let sys_time = SystemTime::now(); let difference = sys_time.duration_since(sys_time) .expect("SystemTime::duration_since failed"); println!("{:?}", difference);
pub fn elapsed(&self) -> Result<Duration, SystemTimeError>
1.8.0[src]
pub fn elapsed(&self) -> Result<Duration, SystemTimeError>
Returns the amount of time elapsed since this system time was created.
This function may fail as the underlying system clock is susceptible to
drift and updates (e.g. the system clock could go backwards), so this
function may not always succeed. If successful, Ok
(
Duration
)
is
returned where the duration represents the amount of time elapsed from
this time measurement to the current time.
Returns an Err
if self
is later than the current system time, and
the error contains how far from the current system time self
is.
Examples
use std::thread::sleep; use std::time::{Duration, SystemTime}; let sys_time = SystemTime::now(); let one_sec = Duration::from_secs(1); sleep(one_sec); assert!(sys_time.elapsed().unwrap() >= one_sec);
Trait Implementations
impl Debug for Timestamp
[src]
impl Debug for Timestamp
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl PartialEq for Timestamp
[src]
impl PartialEq for Timestamp
fn eq(&self, __arg_0: &Timestamp) -> bool
[src]
fn eq(&self, __arg_0: &Timestamp) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Timestamp) -> bool
[src]
fn ne(&self, __arg_0: &Timestamp) -> bool
This method tests for !=
.
impl Eq for Timestamp
[src]
impl Eq for Timestamp
impl Clone for Timestamp
[src]
impl Clone for Timestamp
fn clone(&self) -> Timestamp
[src]
fn clone(&self) -> Timestamp
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl AsRef<SystemTime> for Timestamp
[src]
impl AsRef<SystemTime> for Timestamp
fn as_ref(&self) -> &SystemTime
[src]
fn as_ref(&self) -> &SystemTime
Performs the conversion.
impl Deref for Timestamp
[src]
impl Deref for Timestamp
type Target = SystemTime
The resulting type after dereferencing.
fn deref(&self) -> &SystemTime
[src]
fn deref(&self) -> &SystemTime
Dereferences the value.
impl Into<SystemTime> for Timestamp
[src]
impl Into<SystemTime> for Timestamp
fn into(self) -> SystemTime
[src]
fn into(self) -> SystemTime
Performs the conversion.
impl From<SystemTime> for Timestamp
[src]
impl From<SystemTime> for Timestamp
fn from(dur: SystemTime) -> Timestamp
[src]
fn from(dur: SystemTime) -> Timestamp
Performs the conversion.
impl FromStr for Timestamp
[src]
impl FromStr for Timestamp
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Timestamp, Self::Err>
[src]
fn from_str(s: &str) -> Result<Timestamp, Self::Err>
Parses a string s
to return a value of this type. Read more
impl Display for Timestamp
[src]
impl Display for Timestamp