pub struct TimeDiff { /* private fields */ }
Expand description

A wrapper type associated with locale and to info.

Implementations

Receive a duration string from input and initiate a TimeDiff struct.

And the duration string should be a human-readable string like 3d and etc. more human-readable duration detail -> humantime

Exmaple
use timediff::*;
assert_eq!(TimeDiff::to_diff(String::from("-10s")).parse(),Ok(String::from("a few seconds ago")))

Receive a std duration and initiate a TimeDiff struct.

Exmaple
use timediff::*;
use std::time::Duration;
assert_eq!(TimeDiff::to_diff_duration(Duration::new(30 * 60, 0)).parse(),Ok(String::from("in 30 minutes")))

Change the locale used for the diff operation on TimeDiff. Default locale is en-US, supports zh-CN, tr-TR, ru-RU and etc. if a custom locale is not supported currently, will return a not found error.

Exmaple
use timediff::*;
use timediff::TimeDiffError as Error;
assert_eq!(
    TimeDiff::to_diff(String::from("-10s"))
        .locale(String::from("zh-CN"))
        .unwrap()
        .parse(),
    Ok(String::from("几秒前"))
);

assert_eq!(
    TimeDiff::to_diff(String::from("10day")).locale(String::from("unknown")),
    Err(Error::NotFoundLocale(String::from("unknown")))
);

Parses and prints a human-readable string representing the difference between two timestamps (a period of a duration)

Exmaple
use timediff::*;
assert_eq!(TimeDiff::to_diff(String::from("-10s")).parse(),Ok(String::from("a few seconds ago")))

Trait Implementations

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.