Skip to content

padding with negative values in strftime produces an unexpected result #485

@BurntSushi

Description

@BurntSushi

Reproduction:

use jiff::civil;

fn main() -> anyhow::Result<()> {
    let zdt =
        civil::date(-2025, 1, 13).at(5, 0, 0, 0).in_tz("America/New_York")?;
    println!("{}", zdt.strftime("%_6Y"));

    Ok(())
}

Has this output:

-  2025

But it should be:

 -2025

Note that there is also an issue when zero padding is used. Specifically, this program:

use jiff::civil;

fn main() -> anyhow::Result<()> {
    let zdt =
        civil::date(-2025, 1, 13).at(5, 0, 0, 0).in_tz("America/New_York")?;
    println!("{}", zdt.strftime("%06Y"));

    Ok(())
}

Has this output:

-002025

But it should be:

-02025

For reference, GNU date behaves as expected:

$ date +'%06Y' -d '@-99999999999'
-01199
$ date +'%_6Y' -d '@-99999999999'
 -1199

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions