chrono icon indicating copy to clipboard operation
chrono copied to clipboard

NaiveTime parsing bug when seconds are 60

Open wcarmon opened this issue 1 year ago • 1 comments

Here's an minimal recreation

        // -- passes as expected since seconds are too large
        assert_eq!(None, NaiveTime::from_hms_opt(11, 22, 60));

        // -- bug:  should pass because seconds are too large
        assert!(NaiveTime::parse_from_str("11:22:60", "%H:%M:%S").is_err());

At a minimum, we have inconsistent handling for seconds that are too large.

Here's a playground link with the same assertions:

  • https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a17c15ee9e92ede3d21e342f91a2241e

wcarmon avatar Aug 21 '24 13:08 wcarmon

So this is an interesting case because there is some support for leap seconds in chrono, and we represent those as having a 60th second. However, apparently we might not allow parsing the 60th second, which may or may not be a defensible choice. The inconsistency is unfortunate, but I honestly don't have a strong opinion on how to improve this.

djc avatar Aug 26 '24 11:08 djc