Using unit 'week' requires that a relative reference time be given, but none was provided #84
-
Hi, 👋🏽 Why this is the case? let dt = 1.weeks();
dbg!(&dt);
let dt = dt.total(Unit::Second);
dbg!(&dt);
let dt = chrono::Duration::weeks(1);
dbg!(&dt);
let dt = dt.num_seconds();
dbg!(&dt); [src/main.rs:21:5] &dt = P1w
[src/main.rs:23:5] &dt = Err(
Error {
inner: ErrorInner {
kind: Adhoc(
using unit 'week' requires that a relative reference time be given, but none was provided,
),
cause: None,
},
},
)
[src/main.rs:26:5] &dt = TimeDelta {
secs: 604800,
nanos: 0,
}
[src/main.rs:28:5] &dt = 604800 |
Beta Was this translation helpful? Give feedback.
Answered by
BurntSushi
Aug 8, 2024
Replies: 2 comments 4 replies
-
Explained here |
Beta Was this translation helpful? Give feedback.
1 reply
-
I have successfully ported |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:Has this output:
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.