Skip to content
Discussion options

You must be logged in to vote

If you're looking to parse 2024-122, then that can be done with Jiff's strptime APIs:

use jiff::civil;

fn main() -> anyhow::Result<()> {
    let date = civil::Date::strptime("%Y-%j", "2024-122")?;
    assert_eq!(date, civil::date(2024, 5, 1));

    Ok(())
}

But it sounds like you are owning the parsing. In that case, you'll want to use Date::with to do those sorts of manipulations. It returns a builder which lets you set a number of fields. The with APIs are available on all datetime types, including on Zoned. Here's how to do it:

use jiff::civil;

fn main() -> anyhow::Result<()> {
    let date =
        civil::Date::new(2024, 1, 1)?.with().day_of_year(122).build()?;
    assert_eq!(date,

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@soulstompp
Comment options

Answer selected by BurntSushi
Comment options

You must be logged in to vote
4 replies
@soulstompp
Comment options

@BurntSushi
Comment options

@soulstompp
Comment options

@BurntSushi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants