Struct chrono::duration::Duration [] [src]

pub struct Duration { /* fields omitted */ }

ISO 8601 time duration with nanosecond precision. This also allows for the negative duration; see individual methods for details.

Methods

impl Duration
[src]

[src]

Makes a new Duration with given number of weeks. Equivalent to Duration::seconds(weeks * 7 * 24 * 60 * 60) with overflow checks. Panics when the duration is out of bounds.

[src]

Makes a new Duration with given number of days. Equivalent to Duration::seconds(days * 24 * 60 * 60) with overflow checks. Panics when the duration is out of bounds.

[src]

Makes a new Duration with given number of hours. Equivalent to Duration::seconds(hours * 60 * 60) with overflow checks. Panics when the duration is out of bounds.

[src]

Makes a new Duration with given number of minutes. Equivalent to Duration::seconds(minutes * 60) with overflow checks. Panics when the duration is out of bounds.

[src]

Makes a new Duration with given number of seconds. Panics when the duration is more than i64::MAX milliseconds or less than i64::MIN milliseconds.

[src]

Makes a new Duration with given number of milliseconds.

[src]

Makes a new Duration with given number of microseconds.

[src]

Makes a new Duration with given number of nanoseconds.

[src]

Runs a closure, returning the duration of time it took to run the closure.

[src]

Returns the total number of whole weeks in the duration.

[src]

Returns the total number of whole days in the duration.

[src]

Returns the total number of whole hours in the duration.

[src]

Returns the total number of whole minutes in the duration.

[src]

Returns the total number of whole seconds in the duration.

[src]

Returns the total number of whole milliseconds in the duration,

[src]

Returns the total number of whole microseconds in the duration, or None on overflow (exceeding 263 microseconds in either direction).

[src]

Returns the total number of whole nanoseconds in the duration, or None on overflow (exceeding 263 nanoseconds in either direction).

[src]

Add two durations, returning None if overflow occurred.

[src]

Subtract two durations, returning None if overflow occurred.

[src]

The minimum possible Duration: i64::MIN milliseconds.

[src]

The maximum possible Duration: i64::MAX milliseconds.

[src]

A duration where the stored seconds and nanoseconds are equal to zero.

[src]

Returns true if the duration equals Duration::zero().

[src]

Creates a time::Duration object from std::time::Duration

This function errors when original duration is larger than the maximum value supported for this type.

[src]

Creates a std::time::Duration object from time::Duration

This function errors when duration is less than zero. As standard library implementation is limited to non-negative values.

Trait Implementations

impl Sub<Duration> for Duration
[src]

The resulting type after applying the - operator.

[src]

Performs the - operation.

impl Sub<Duration> for SteadyTime
[src]

The resulting type after applying the - operator.

[src]

Performs the - operation.

impl Sub<Duration> for Tm
[src]

The resulting type after applying the - operator.

[src]

The resulting Tm is in UTC.

impl Sub<Duration> for Timespec
[src]

The resulting type after applying the - operator.

[src]

Performs the - operation.

impl PartialOrd<Duration> for Duration
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Mul<i32> for Duration
[src]

The resulting type after applying the * operator.

[src]

Performs the * operation.

impl Debug for Duration
[src]

[src]

Formats the value using the given formatter. Read more

impl Copy for Duration
[src]

impl Clone for Duration
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Div<i32> for Duration
[src]

The resulting type after applying the / operator.

[src]

Performs the / operation.

impl Ord for Duration
[src]

[src]

This method returns an Ordering between self and other. Read more

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl Display for Duration
[src]

[src]

Formats the value using the given formatter. Read more

impl Eq for Duration
[src]

impl Add<Duration> for SteadyTime
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl Add<Duration> for Tm
[src]

The resulting type after applying the + operator.

[src]

The resulting Tm is in UTC.

impl Add<Duration> for Duration
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl Add<Duration> for Timespec
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl PartialEq<Duration> for Duration
[src]

[src]

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

[src]

This method tests for !=.

impl Neg for Duration
[src]

The resulting type after applying the - operator.

[src]

Performs the unary - operation.

impl Add<Duration> for NaiveDate
[src]

An addition of Duration to NaiveDate discards the fractional days, rounding to the closest integral number of days towards Duration::zero().

Panics on underflow or overflow. Use NaiveDate::checked_add to detect that.

Example

use chrono::{NaiveDate, Duration};

let ymd = |y,m,d| NaiveDate::from_ymd(y, m, d);
assert_eq!(ymd(2014, 1, 1) + Duration::zero(),             ymd(2014, 1, 1));
assert_eq!(ymd(2014, 1, 1) + Duration::seconds(86399),     ymd(2014, 1, 1));
assert_eq!(ymd(2014, 1, 1) + Duration::seconds(-86399),    ymd(2014, 1, 1));
assert_eq!(ymd(2014, 1, 1) + Duration::days(1),            ymd(2014, 1, 2));
assert_eq!(ymd(2014, 1, 1) + Duration::days(-1),           ymd(2013, 12, 31));
assert_eq!(ymd(2014, 1, 1) + Duration::days(364),          ymd(2014, 12, 31));
assert_eq!(ymd(2014, 1, 1) + Duration::days(365*4 + 1),    ymd(2018, 1, 1));
assert_eq!(ymd(2014, 1, 1) + Duration::days(365*400 + 97), ymd(2414, 1, 1));

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl Sub<Duration> for NaiveDate
[src]

A subtraction of Duration from NaiveDate discards the fractional days, rounding to the closest integral number of days towards Duration::zero().

Panics on underflow or overflow. Use NaiveDate::checked_sub to detect that.

Example

use chrono::{NaiveDate, Duration};

let ymd = |y,m,d| NaiveDate::from_ymd(y, m, d);
assert_eq!(ymd(2014, 1, 1) - Duration::zero(),             ymd(2014, 1, 1));
assert_eq!(ymd(2014, 1, 1) - Duration::seconds(86399),     ymd(2014, 1, 1));
assert_eq!(ymd(2014, 1, 1) - Duration::seconds(-86399),    ymd(2014, 1, 1));
assert_eq!(ymd(2014, 1, 1) - Duration::days(1),            ymd(2013, 12, 31));
assert_eq!(ymd(2014, 1, 1) - Duration::days(-1),           ymd(2014, 1, 2));
assert_eq!(ymd(2014, 1, 1) - Duration::days(364),          ymd(2013, 1, 2));
assert_eq!(ymd(2014, 1, 1) - Duration::days(365*4 + 1),    ymd(2010, 1, 1));
assert_eq!(ymd(2014, 1, 1) - Duration::days(365*400 + 97), ymd(1614, 1, 1));

The resulting type after applying the - operator.

[src]

Performs the - operation.

impl Add<Duration> for NaiveTime
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl Sub<Duration> for NaiveTime
[src]

The resulting type after applying the - operator.

[src]

Performs the - operation.

impl Add<Duration> for NaiveDateTime
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl Sub<Duration> for NaiveDateTime
[src]

The resulting type after applying the - operator.

[src]

Performs the - operation.

impl<Tz: TimeZone> Add<Duration> for Date<Tz>
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl<Tz: TimeZone> Sub<Duration> for Date<Tz>
[src]

The resulting type after applying the - operator.

[src]

Performs the - operation.

impl<Tz: TimeZone> Add<Duration> for DateTime<Tz>
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl<Tz: TimeZone> Sub<Duration> for DateTime<Tz>
[src]

The resulting type after applying the - operator.

[src]

Performs the - operation.