Skip to content

unexpected behavior of duration_trunc with DateTime<FixedOffset> #584

@kkazuo

Description

@kkazuo
extern crate chrono; // 0.4.19

use chrono::{FixedOffset, Utc, Duration, DurationRound, Timelike};

fn main() {
    let t = Utc::now();
    let t = t.with_timezone(&FixedOffset::east(9 * 3600));
    let t = t.duration_trunc(Duration::days(1)).unwrap();
    assert_eq!(t.second(), 0);
    assert_eq!(t.minute(), 0);
    assert_eq!(t.hour(), 0); // I expect 0, but got 9.
}
 Compiling playground v0.0.1 (/playground)
    Finished dev [unoptimized + debuginfo] target(s) in 1.72s
     Running `target/debug/playground`
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `9`,
 right: `0`', src/main.rs:11:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I want to get the truncated time with timezone aware.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions