Struct chrono_elapsed::Elapsed[][src]

pub struct Elapsed {
    pub duration: Duration,
    pub passed: bool,
    pub cache: HashMap<TimeFrame, (Cow<'static, str>, i64)>,
    // some fields omitted
}
Expand description

Provides a context-aware DateTime object; a given DateTime is made aware in the context of the current DateTime (or in the context of a given DateTime, see new_with_context.)

Allows you to easily obtain information such as datetime is due in 42 minutes and 30 seconds, datetime is overdue by 3 days and 2 hours, or when given context, time between x and y is 42 years and 9 months.

Aliased as DueDateTime out of the box in case that makes more sense in your context.

Fields

duration: Duration

Also known as the diff, difference in time between a given DateTime and the DateTime used for context.

passed: bool

If the date has already passed, or elapsed, it’s no longer due so we can skip some processing, and format a more meaningful message on display.

cache: HashMap<TimeFrame, (Cow<'static, str>, i64)>

A cache of diff values. Key being the sec/min/hour/day, etc. identifier. Value being a tuple of the diff value as a string in pos 0, and numeric value in pos 1.

Implementations

Construct a new object.

Construct a new object from a Date rather than DateTime.

Construct a new object and then add Local timezone.

Construct a new object from a Date then add Local timezone.

Construct a new object with a custom context, rather than the default now.

Construct a new object from a Date with a custom context.

Set the Elapsed’s datetime_context. Will clear cached diff values.

Set the Elapsed’s datetime. Will clear cached diff values.

Set the Elapsed’s date. Will clear cached diff values.

Populate cache with contextually aware TimeFrames. Discards “irrelevant” time frames, for example if date is due in more than a year, we’ll only store 1y 6m as opposed to 1y 6m 2w 4d.

Helper function to insert a value for a TimeFrame into the cache.

Get number of years.

Get years between DateTime and DateTime given for context as elapsed style tuple.

Get years between DateTime and DateTime given for context. Can be chained to string together multiple values of your choosing.

let date = self.years_and().months_and().weeks();
println!("{}", date);
let silly_date = self.years_and().seconds();
println!("{}", silly_date);

Results in 1y 6m 2w the first time, or something silly the second time..

Get number of months.

Get months between DateTime and DateTime given for context as elapsed style tuple.

Get weeks between DateTime and DateTime given for context as elapsed style tuple.

Chrono provides a method to get numeric value alone, which is exposed by Elapsed struct duration field.

Get days between DateTime and DateTime given for context as elapsed style tuple.

Chrono provides a method to get numeric value alone, which is exposed by Elapsed struct duration field.

Get hours between DateTime and DateTime given for context as elapsed style tuple.

Chrono provides a method to get numeric value alone, which is exposed by Elapsed struct duration field.

Get minutes between DateTime and DateTime given for context as elapsed style tuple.

Chrono provides a method to get numeric value alone, which is exposed by Elapsed struct duration field.

Get seconds between DateTime and DateTime given for context as elapsed style tuple.

Chrono provides a method to get numeric value alone, which is exposed by Elapsed struct duration field.

This fn is intended to be used similarly to chaining, like so:

let date = self.seconds_and().through_til(&TimeFrame::Months);
println!("{}", date);

Resulting in seconds, minutes, hours, days, weeks and months being set in cache, and then subsequently printed as (in) 3y 2w 4d 12hr 32min 42sec (ago).

Create a clone of our cache containing the values at time of collection.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Construct from localised Date.

Construct from UTC Date.

Construct from localised DateTime.

Construct from UTC DateTime.

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 resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

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.