Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect handling when clocks are moved backward? #23

Closed
breezewish opened this issue Jul 3, 2018 · 4 comments
Closed

Incorrect handling when clocks are moved backward? #23

breezewish opened this issue Jul 3, 2018 · 4 comments

Comments

@breezewish
Copy link

Consider 06 November, 2011 01:59:59 AM in America/Los_Angeles:

let tz: chrono_tz::Tz = "America/Los_Angeles".parse().unwrap();
let dt = tz.ymd_opt(2011, 11, 6).and_hms_opt(1, 59, 59);
println!("{:?}", dt);

According to time zone information:

After Sunday, 06 November, 2011 01:59:59 AM:
Clocks were moved backward to become Sunday, 06 November, 2011 01:00:00 AM

So 06 November, 2011 01:59:59 is ambiguous, but the output is None.

@breezewish
Copy link
Author

Also, when using local, the problem does not exist:

    let t = Local.ymd_opt(1988, 09, 10).and_hms_opt(23, 59, 59);
    println!("{}", t.unwrap().timestamp());

    let tz: Tz = "Asia/Shanghai".parse().unwrap();
    let t = tz.ymd_opt(1988, 09, 10).and_hms_opt(23, 59, 59);
    println!("{}", t.unwrap().timestamp());

My time zone is Asia/Shanghai and the first one will success and the second one will fail.

@breezewish
Copy link
Author

A friendly ping

@kennytm
Copy link
Contributor

kennytm commented Apr 23, 2019

This issue has nothing to do with chrono-tz, the implementation properly returns LocalResult::Ambiguous. The problem is that chrono's implementation of LocalResult::and_hms_opt discards the Ambiguous result.

Local "works" because Local never returns anything besides LocalResult::Single, even in case of non-existing time (due to the tm → time_t → tm roundtrip):

use chrono::*;

fn main() {
	let dt1 = chrono_tz::America::Los_Angeles.ymd_opt(2018, 3, 11).and_hms_opt(2, 15, 0);
	let dt2 = Local.ymd_opt(2018, 3, 11).and_hms_opt(2, 15, 0);
	println!("{:?}", dt1);
        // None 👌 
	println!("{:?}", dt2);
        // Single(2018-03-11T03:15:00-07:00) 😕 
}

@sparky8251
Copy link

This seems related to my issue, chrono #318. I found other related issues around this as well.

@pitdicker pitdicker closed this as not planned Won't fix, can't repro, duplicate, stale Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants