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

parse_datetime fails to parse a string comprising both reference date and a time delta #104

Open
jfinkels opened this issue Jan 19, 2025 · 0 comments

Comments

@jfinkels
Copy link
Contributor

jfinkels commented Jan 19, 2025

Steps to reproduce: put this failing test case in the #[cfg(test)] module in lib.rs and then run cargo test test_parse_datetime_reference_date_and_time_delta:

        #[test]
        fn test_parse_datetime_reference_date_and_time_delta() {
            // $ TZ=UTC0 date -I -d "1996-02-29 +1 year"
            std::env::set_var("TZ", "UTC0");
            let actual = parse_datetime("1996-02-29 +1 year").expect("parse failed");

            // 1997-03-01
            let expected = chrono::NaiveDate::from_ymd_opt(1997, 3, 1)
                .unwrap()
                .and_hms_opt(0, 0, 0)
                .unwrap()
                .and_utc();
            assert_eq!(actual, expected);
        }

What happens now: the test fails because parse_datetime() returns an error.

What I expected to happen: the test passes, with date "1996-02-29" parsed as the reference date, "+1 year" as the additional time delta to add, and the returned date being "1997-03-01" (with placeholder time of 00:00:00 in timezone UTC).

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

1 participant