Skip to content

parse_relative_time_at_date() fails to account for leap day when adding one year #98

Closed
@jfinkels

Description

@jfinkels

parse_relative_time_at_date() fails to account for leap days when computing "leap day + 1 year" or "leap day + 12 months".

Test case for parse_relative_time.rs:

    // One year after a leap day is the following day in the next year:
    //
    //     $ date -I --date '1996-02-29 +1 year'
    //     1997-03-01
    //     $ date -I --date '1996-02-29 +12 months'
    //     1997-03-01
    //     $ date -I --date '1996-02-29 +366 days'
    //     1997-03-01
    //
    #[test]
    fn test_leap_year() {
        let datetime = Utc.from_utc_datetime(&NaiveDate::from_ymd_opt(1996, 2, 29).unwrap().into());
        let expected = Utc.from_utc_datetime(&NaiveDate::from_ymd_opt(1997, 3, 1).unwrap().into());
        assert_eq!(
            parse_relative_time_at_date(datetime, "1 year").unwrap(),
            expected
        );
        assert_eq!(
            parse_relative_time_at_date(datetime, "12 months").unwrap(),
            expected
        );
        assert_eq!(
            parse_relative_time_at_date(datetime, "366 days").unwrap(),
            expected
        );
    }

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