Trait rubedo::chrono::DurationExt

source ·
pub trait DurationExt {
Show 21 associated constants and 5 methods const MAX_NANOSECONDS: i64 = 9_223_372_036_854_775_807i64; const MAX_NANOSECONDS_FULL: i128 = 9_223_372_036_854_775_807_000_000i128; const MAX_MICROSECONDS: i64 = 9_223_372_036_854_775_807i64; const MAX_MICROSECONDS_FULL: i128 = 9_223_372_036_854_775_807_000i128; const MAX_MILLISECONDS: i64 = 9_223_372_036_854_775_807i64; const MAX_SECONDS: i64 = 9_223_372_036_854_775i64; const MAX_MINUTES: i64 = 153_722_867_280_912i64; const MAX_HOURS: i64 = 2_562_047_788_015i64; const MAX_DAYS: i64 = 106_751_991_167i64; const MAX_WEEKS: i64 = 15_250_284_452i64; const MIN_NANOSECONDS: i64 = -9_223_372_036_854_775_808i64; const MIN_NANOSECONDS_FULL: i128 = -9_223_372_036_854_775_807_000_000i128; const MIN_MICROSECONDS: i64 = -9_223_372_036_854_775_808i64; const MIN_MICROSECONDS_FULL: i128 = -9_223_372_036_854_775_807_000i128; const MIN_MILLISECONDS: i64 = -9_223_372_036_854_775_807i64; const MIN_SECONDS: i64 = -9_223_372_036_854_775i64; const MIN_MINUTES: i64 = -153_722_867_280_912i64; const MIN_HOURS: i64 = -2_562_047_788_015i64; const MIN_DAYS: i64 = -106_751_991_167i64; const MIN_WEEKS: i64 = -15_250_284_452i64; const UNITS: [(i64, &'static str); 7] = _; // Required methods fn humanize(&self) -> String; fn nanoseconds_full(nanoseconds: i128) -> Option<Self> where Self: Sized; fn microseconds_full(microseconds: i128) -> Option<Self> where Self: Sized; fn num_nanoseconds_full(&self) -> i128; fn num_microseconds_full(&self) -> i128;
}
Expand description

This trait provides additional functionality to Duration.

Provided Associated Constants§

source

const MAX_NANOSECONDS: i64 = 9_223_372_036_854_775_807i64

The maximum number of nanoseconds that can be represented by a Duration when expressed alone. Note that this is not the maximum number of nanoseconds that can actually be stored by a Duration, but the maximum number that can be expressed as an individual component. The Duration struct stores its value as a number of seconds and nanoseconds, but artificially limits the number of seconds so that the milliseconds will never overflow. The maximum number of nanoseconds that can be stored is therefore the maximum number of seconds multiplied by one billion. However, the expression of this full value as nanoseconds is not possible, and therefore this constant indicates the maximum number of nanoseconds that can be expressed with current Chrono functionality.

source

const MAX_NANOSECONDS_FULL: i128 = 9_223_372_036_854_775_807_000_000i128

The maximum number of nanoseconds that can be represented by a Duration. Note that this is the maximum number of nanoseconds that can actually be stored by a Duration, which is more than can be expressed alone using standard Chrono functionality.

source

const MAX_MICROSECONDS: i64 = 9_223_372_036_854_775_807i64

The maximum number of microseconds that can be represented by a Duration when expressed alone. Note that this is not the maximum number of microseconds that can actually be stored by a Duration, but the maximum number that can be expressed as an individual component. The Duration struct stores its value as a number of seconds and nanoseconds, but artificially limits the number of seconds so that the milliseconds will never overflow. The maximum number of microseconds that can be stored is therefore the maximum number of seconds multiplied by one million. However, the expression of this full value as microseconds is not possible, and therefore this constant indicates the maximum number of microseconds that can be expressed with current Chrono functionality.

source

const MAX_MICROSECONDS_FULL: i128 = 9_223_372_036_854_775_807_000i128

The maximum number of microseconds that can be represented by a Duration. Note that this is the maximum number of microseconds that can actually be stored by a Duration, which is more than can be expressed alone using standard Chrono functionality.

source

const MAX_MILLISECONDS: i64 = 9_223_372_036_854_775_807i64

The maximum number of milliseconds that can be represented by a Duration. The Duration struct stores its value as a number of seconds and nanoseconds, but artificially limits the number of seconds so that the milliseconds will never overflow. The maximum number of milliseconds that can be stored is therefore the maximum number of seconds multiplied by one thousand, and the expression of this full value as milliseconds is possible.

source

const MAX_SECONDS: i64 = 9_223_372_036_854_775i64

The maximum number of seconds that can be represented by a Duration. The Duration struct stores its value as a number of seconds and nanoseconds, but artificially limits the number of seconds so that the milliseconds will never overflow.

source

const MAX_MINUTES: i64 = 153_722_867_280_912i64

The maximum number of minutes that can be represented by a Duration.

source

const MAX_HOURS: i64 = 2_562_047_788_015i64

The maximum number of hours that can be represented by a Duration.

source

const MAX_DAYS: i64 = 106_751_991_167i64

The maximum number of days that can be represented by a Duration.

source

const MAX_WEEKS: i64 = 15_250_284_452i64

The maximum number of weeks that can be represented by a Duration.

source

const MIN_NANOSECONDS: i64 = -9_223_372_036_854_775_808i64

The minimum number of nanoseconds that can be represented by a Duration when expressed alone. Note that this is not the minimum number of nanoseconds that can actually be stored by a Duration, but the minimum number that can be expressed as an individual component. The Duration struct stores its value as a number of seconds and nanoseconds, but artificially limits the number of seconds so that the milliseconds will never overflow. The minimum number of nanoseconds that can be stored is therefore the minimum number of seconds multiplied by one billion. However, the expression of this full value as nanoseconds is not possible, and therefore this constant indicates the minimum number of nanoseconds that can be expressed with current Chrono functionality.

source

const MIN_NANOSECONDS_FULL: i128 = -9_223_372_036_854_775_807_000_000i128

The minimum number of nanoseconds that can be represented by a Duration. Note that this is the minimum number of nanoseconds that can actually be stored by a Duration, which is more than can be expressed alone using standard Chrono functionality. The range here notably is from -i64::MAX and not i64::MIN, due to changes in https://github.com/chronotope/chrono/pull/1334.

source

const MIN_MICROSECONDS: i64 = -9_223_372_036_854_775_808i64

The minimum number of microseconds that can be represented by a Duration when expressed alone. Note that this is not the minimum number of microseconds that can actually be stored by a Duration, but the minimum number that can be expressed as an individual component. The Duration struct stores its value as a number of seconds and nanoseconds, but artificially limits the number of seconds so that the milliseconds will never overflow. The minimum number of microseconds that can be stored is therefore the minimum number of seconds multiplied by one million. However, the expression of this full value as microseconds is not possible, and therefore this constant indicates the minimum number of microseconds that can be expressed with current Chrono functionality.

source

const MIN_MICROSECONDS_FULL: i128 = -9_223_372_036_854_775_807_000i128

The minimum number of microseconds that can be represented by a Duration. Note that this is the minimum number of microseconds that can actually be stored by a Duration, which is more than can be expressed alone using standard Chrono functionality. The range here notably is from -i64::MAX and not i64::MIN, due to changes in https://github.com/chronotope/chrono/pull/1334.

source

const MIN_MILLISECONDS: i64 = -9_223_372_036_854_775_807i64

The minimum number of milliseconds that can be represented by a Duration. The Duration struct stores its value as a number of seconds and nanoseconds, but artificially limits the number of seconds so that the milliseconds will never overflow. The minimum number of milliseconds that can be stored is therefore the minimum number of seconds multiplied by one thousand, and the expression of this full value as milliseconds is possible. The range here notably is from -i64::MAX and not i64::MIN, due to changes in https://github.com/chronotope/chrono/pull/1334.

source

const MIN_SECONDS: i64 = -9_223_372_036_854_775i64

The minimum number of seconds that can be represented by a Duration. The Duration struct stores its value as a number of seconds and nanoseconds, but artificially limits the number of seconds so that the milliseconds will never overflow.

source

const MIN_MINUTES: i64 = -153_722_867_280_912i64

The minimum number of minutes that can be represented by a Duration.

source

const MIN_HOURS: i64 = -2_562_047_788_015i64

The minimum number of hours that can be represented by a Duration.

source

const MIN_DAYS: i64 = -106_751_991_167i64

The minimum number of days that can be represented by a Duration.

source

const MIN_WEEKS: i64 = -15_250_284_452i64

The minimum number of weeks that can be represented by a Duration.

source

const UNITS: [(i64, &'static str); 7] = _

The units used by humanize(). These determine the units that will be used to represent a duration, with the largest possible unit being used.

Required Methods§

source

fn humanize(&self) -> String

Returns a human-readable string representation of a Duration.

This will indicate the Duration as an expression of the largest unit available. For example, if the duration is 1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds, it will return “1 year”.

source

fn nanoseconds_full(nanoseconds: i128) -> Option<Self>
where Self: Sized,

Make a new Duration with the given number of nanoseconds.

This function is necessary because although the Duration struct stores its value internally as seconds and nanoseconds, the nanoseconds() method only accepts the number of nanoseconds as an i64, which is not large enough to express the full range of nanoseconds that can be stored by a Duration instance. This function therefore accepts the number of nanoseconds as an i128, which is large enough to express the full range of nanoseconds that can be stored, and creates a Duration instance appropriately.

§Errors

This function will return None if the number of nanoseconds is greater than MAX_NANOSECONDS_FULL or less than MIN_NANOSECONDS_FULL. This is not quite the same as Chrono’s behaviour, which panics under similar conditions, but panics are undesirable in library code and hence this deviation seems justifiable.

source

fn microseconds_full(microseconds: i128) -> Option<Self>
where Self: Sized,

Make a new Duration with the given number of microseconds.

This function is necessary because although the Duration struct stores its value internally as seconds and microseconds, the microseconds() method only accepts the number of microseconds as an i64, which is not large enough to express the full range of microseconds that can be stored by a Duration instance. This function therefore accepts the number of microseconds as an i128, which is large enough to express the full range of microseconds that can be stored, and creates a Duration instance appropriately.

§Errors

This function will return None if the number of microseconds is greater than MAX_MICROSECONDS_FULL or less than MIN_MICROSECONDS_FULL. This is not quite the same as Chrono’s behaviour, which panics under similar conditions, but panics are undesirable in library code and hence this deviation seems justifiable.

source

fn num_nanoseconds_full(&self) -> i128

Returns the total number of nanoseconds in the Duration instance.

This function is necessary because although the Duration struct stores its value internally as seconds and nanoseconds, the num_nanoseconds() method returns the nanoseconds as an i64, which is not large enough to express the full range of nanoseconds that can be stored by a Duration instance. This function therefore returns the nanoseconds as an i128, which is large enough to express the full range of nanoseconds that can be stored.

source

fn num_microseconds_full(&self) -> i128

Returns the total number of microseconds in the Duration instance.

This function is necessary because although the Duration struct stores its value internally as seconds and nanoseconds, the num_microseconds() method returns the microseconds as an i64, which is not large enough to express the full range of microseconds that can be stored by a Duration instance. This function therefore returns the microseconds as an i128, which is large enough to express the full range of microseconds that can be stored.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl DurationExt for Duration

Implementors§