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§
sourceconst MAX_NANOSECONDS: i64 = 9_223_372_036_854_775_807i64
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.
sourceconst MAX_NANOSECONDS_FULL: i128 = 9_223_372_036_854_775_807_000_000i128
const MAX_NANOSECONDS_FULL: i128 = 9_223_372_036_854_775_807_000_000i128
sourceconst MAX_MICROSECONDS: i64 = 9_223_372_036_854_775_807i64
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.
sourceconst MAX_MICROSECONDS_FULL: i128 = 9_223_372_036_854_775_807_000i128
const MAX_MICROSECONDS_FULL: i128 = 9_223_372_036_854_775_807_000i128
sourceconst MAX_MILLISECONDS: i64 = 9_223_372_036_854_775_807i64
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.
sourceconst MAX_SECONDS: i64 = 9_223_372_036_854_775i64
const MAX_SECONDS: i64 = 9_223_372_036_854_775i64
sourceconst MAX_MINUTES: i64 = 153_722_867_280_912i64
const MAX_MINUTES: i64 = 153_722_867_280_912i64
The maximum number of minutes that can be represented by a Duration
.
sourceconst MAX_HOURS: i64 = 2_562_047_788_015i64
const MAX_HOURS: i64 = 2_562_047_788_015i64
The maximum number of hours that can be represented by a Duration
.
sourceconst MAX_DAYS: i64 = 106_751_991_167i64
const MAX_DAYS: i64 = 106_751_991_167i64
The maximum number of days that can be represented by a Duration
.
sourceconst MAX_WEEKS: i64 = 15_250_284_452i64
const MAX_WEEKS: i64 = 15_250_284_452i64
The maximum number of weeks that can be represented by a Duration
.
sourceconst MIN_NANOSECONDS: i64 = -9_223_372_036_854_775_808i64
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.
sourceconst MIN_NANOSECONDS_FULL: i128 = -9_223_372_036_854_775_807_000_000i128
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.
sourceconst MIN_MICROSECONDS: i64 = -9_223_372_036_854_775_808i64
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.
sourceconst MIN_MICROSECONDS_FULL: i128 = -9_223_372_036_854_775_807_000i128
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.
sourceconst MIN_MILLISECONDS: i64 = -9_223_372_036_854_775_807i64
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.
sourceconst MIN_SECONDS: i64 = -9_223_372_036_854_775i64
const MIN_SECONDS: i64 = -9_223_372_036_854_775i64
sourceconst MIN_MINUTES: i64 = -153_722_867_280_912i64
const MIN_MINUTES: i64 = -153_722_867_280_912i64
The minimum number of minutes that can be represented by a Duration
.
sourceconst MIN_HOURS: i64 = -2_562_047_788_015i64
const MIN_HOURS: i64 = -2_562_047_788_015i64
The minimum number of hours that can be represented by a Duration
.
sourceconst MIN_DAYS: i64 = -106_751_991_167i64
const MIN_DAYS: i64 = -106_751_991_167i64
The minimum number of days that can be represented by a Duration
.
Required Methods§
sourcefn nanoseconds_full(nanoseconds: i128) -> Option<Self>where
Self: Sized,
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.
sourcefn microseconds_full(microseconds: i128) -> Option<Self>where
Self: Sized,
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.
sourcefn num_nanoseconds_full(&self) -> i128
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.
sourcefn num_microseconds_full(&self) -> i128
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.