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

panic in chrono when parsing the string "12pm" #24

Open
willfindlay opened this issue Jan 16, 2023 · 3 comments
Open

panic in chrono when parsing the string "12pm" #24

willfindlay opened this issue Jan 16, 2023 · 3 comments

Comments

@willfindlay
Copy link

willfindlay commented Jan 16, 2023

See issue title.

Relevant Cargo.lock versions:

[[package]]
name = "chrono"
version = "0.4.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f"
dependencies = [
 "iana-time-zone",
 "js-sys",
 "num-integer",
 "num-traits 0.2.15",
 "serde",
 "time 0.1.45",
 "wasm-bindgen",
 "winapi",
]

[[package]]
name = "chrono-english"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f73d909da7eb4a7d88c679c3f5a1bc09d965754e0adb2e7627426cef96a00d6f"
dependencies = [
 "chrono",
 "scanlex",
]
@willfindlay
Copy link
Author

The following changes to am_pm() fix the bug:

    fn am_pm(name: &str, mut hour: u32) -> DateResult<u32> {
        if name == "pm" {
            if hour != 12 {
                hour += 12;
            }
        } else if name == "am" {
            if hour == 12 {
                hour = 0;
            }
        } else if name != "am" {
            return date_result("expected am or pm");
        }
        Ok(hour)
    }

@conradludgate
Copy link

conradludgate commented Oct 15, 2023

I noticed that my fork, interim, also has this problem.

What isn't immediately clear to me is whether "12pm" should be tonight or this morning. e.g. it's currently 2023-10-15T13:33:00+01:00. Should "12pm" be 2023-10-16T00:00:00+01:00 or 2023-10-15T00:00:00+01:00. My gut feeling tells me that it should choose tonight.

Never mind, 12pm should be midday

conradludgate added a commit to conradludgate/interim that referenced this issue Oct 15, 2023
@stevedonovan
Copy link
Owner

Sorry guys, this is a nasty one and I will fix as soon as I get back from vacation.

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

3 participants