# Trait chrono::DurationRound [−] [src]

    pub trait DurationRound: Sized {
        type Err: Error;
        fn duration_round(self, duration: Duration) -> Result<Self, Self::Err>;
        fn duration_trunc(self, duration: Duration) -> Result<Self, Self::Err>;
    }

Extension trait for rounding or truncating a DateTime by a Duration.

# Limitations

Both rounding and truncating are done via `Duration::num_nanoseconds` and `DateTime::timestamp_nanos`. This means that they will fail if either the `Duration` or the `DateTime` are too big to represented as nanoseconds. They will also fail if the `Duration` is bigger than the timestamp.

## Associated Types

### `type Err: Error` [src]

Error that can occur in rounding or truncating

Loading content...

## Required methods

### `fn duration_round(self, duration: Duration) -> Result<Self, Self::Err>` [src]

Return a copy rounded by Duration.

# Example

    let dt = Utc.ymd(2018, 1, 11).and_hms_milli(12, 0, 0, 154);
    assert_eq!(
        dt.duration_round(Duration::milliseconds(10)).unwrap().to_string(),
        "2018-01-11 12:00:00.150 UTC"
    );
    assert_eq!(
        dt.duration_round(Duration::days(1)).unwrap().to_string(),
        "2018-01-12 00:00:00 UTC"
    );

### `fn duration_trunc(self, duration: Duration) -> Result<Self, Self::Err>` [src]

Return a copy truncated by Duration.

# Example

    let dt = Utc.ymd(2018, 1, 11).and_hms_milli(12, 0, 0, 154);
    assert_eq!(
        dt.duration_trunc(Duration::milliseconds(10)).unwrap().to_string(),
        "2018-01-11 12:00:00.150 UTC"
    );
    assert_eq!(
        dt.duration_trunc(Duration::days(1)).unwrap().to_string(),
        "2018-01-11 00:00:00 UTC"
    );

Loading content...

## Implementors

### `impl<Tz: TimeZone> DurationRound for DateTime<Tz>` [src]

#### `type Err = RoundingError`

#### `fn duration_round(self, duration: Duration) -> Result<Self, Self::Err>` [src]

#### `fn duration_trunc(self, duration: Duration) -> Result<Self, Self::Err>` [src]

Loading content...