Skip to content

Invalid Gregorian dates can be constructed (historical edge case) #630

Description

@mrec

When the Gregorian calendar was first introduced, it advanced 10 days against the Julian one, so Thursday 4 October 1582 was followed by Friday 15 October 1582. Octobers 5 through 14 1582 are therefore not valid Gregorian dates, but the library doesn't take account of this.

What I did:

cargo add jiff i.e. default config

use jiff::civil::Date;

fn main() {
    assert!(Date::new(1582, 10, 4).is_ok());
    assert!(Date::new(1582, 10, 5).is_err());
    assert!(Date::new(1582, 10, 14).is_err());
    assert!(Date::new(1582, 10, 15).is_ok());
}

Expected: all asserts succeed

Actual: the two .is_err() asserts fail

To be clear, I don't have a concrete use case for needing this to be handled correctly, and was just curious after reading the Dates That Don't Exist blog post. But the jiff docs state very clearly that

Every Date value is guaranteed to be a valid Gregorian calendar date.

so I think either that guarantee needs qualification or the code needs some special-casing. I'd be happy to attempt a PR, but don't have any history with the project and assume you'll want to take a view first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions