Open swiftvimla opened 7 months ago
Agreed. We'd love to have that fixed.
I tracked this down to HumanTime::from()
.
❯ (date now) + 5hr
lhs: 2024-03-26T15:58:40.874977-05:00, rhs: 18000000000000
to_expanded_string val: 2024-03-26T20:58:40.874977-05:00
Tue, 26 Mar 2024 20:58:40 -0500 (in 4 hours)
So, that val
in the to_expanded_string
function is being converted to (in 4 hours)
in the HumanTime crate. The datetime math looks correct but the estimate is a little off. Not sure what we can do about it though.
I tried to solve this issue, however I couldn't come up with a good solution. I'll leave the info I found in case it helps.
The following behavior is due to this implementation of chrono-humanize-rs.
> (date now) + 1hr 03/26/2024 08:36:30 AM
Tue, 26 Mar 2024 09:36:30 +0100 (in an hour)
> (date now) + 2hr 03/26/2024 08:36:32 AM
Tue, 26 Mar 2024 10:36:32 +0100 (in 2 hours)
> (date now) + 3hr 03/26/2024 08:36:34 AM
Tue, 26 Mar 2024 11:36:34 +0100 (in 2 hours)
When calculating the difference from the current time, it will be slightly off, resulting in the reproduced example.
~/oss_dev/nushell> (date now) + 3hr 07/24/2024 01:14:49 AM
[crates/nu-protocol/src/value/mod.rs:838:21] HumanTime::from(*val) = HumanTime(
TimeDelta {
secs: 10799,
nanos: 999416966,
},
)
Wed, 24 Jul 2024 04:14:51 +0900 (in 2 hours)
~/oss_dev/nushell> (date now) + 3hr + 1sec 07/24/2024 01:14:51 AM
[crates/nu-protocol/src/value/mod.rs:838:21] HumanTime::from(*val) = HumanTime(
TimeDelta {
secs: 10800,
nanos: 999203834,
},
)
Wed, 24 Jul 2024 04:14:55 +0900 (in 3 hours)
Describe the bug
Nushell helpfully prints datetimes with the absolute value and then a value relative to the current time at the end.
The bug relates to the relative representation, eg.
in 2 hours
. It seems to be rounding values in a (to me at least) non-intuitive way.How to reproduce
Use
date now
and then add a durationExpected behavior
Round off to the nearest hour (or whichever unit is appropriate) when displaying an absolute datetime relative to the current datetime.
Screenshots
No response
Configuration
Additional context
No response