Skip to content

Using unit 'week' requires that a relative reference time be given, but none was provided #84

Answered by BurntSushi
azzamsa asked this question in Q&A
Discussion options

You must be logged in to vote

Yeah basically you need to have a relative date to do transformations like this. Jiff is preventing you from introducing bugs in subtle corner cases. Indeed, chrono-humanize just assumes that all months are 30 days, which is obviously wrong:

use chrono_humanize::{Accuracy, HumanTime, Tense};

fn main() {
    let dt = chrono::Duration::days(31);
    let ht = HumanTime::from(dt);
    let text = ht.to_text_en(Accuracy::Precise, Tense::Present);
    println!("{text}");
}

Has this output:

1 month and 1 day

Some months are 31 days. Some are 29. Some are 28. Some are 30. The only correct way to know the duration of a month is to interpret it relative to a particular date.

Replies: 2 comments 4 replies

Comment options

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

Answer selected by BurntSushi
Comment options

You must be logged in to vote
3 replies
@BurntSushi
Comment options

@azzamsa
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