nushell: `datetime-diff` doesn't work
datetime-diff from the dt standard library module always errors out with:
EDIT from maintainer: this error appears to come when the two dates are the same, e.g. with
datetime-diff (date now) (date now)
which gives
Error: nu::shell::name_not_found
× Name not found
╭─[NU_STDLIB_VIRTUAL_DIR/std/dt.nu:81:1]
81 │ mut current = $current
82 │ $current.millisecond = $current.millisecond + 1_000
· ─────┬─────
· ╰── did you mean 'second'?
83 │ $current.second = $current.second - 1
╰────
I looked at the source code, the issue seems to be caused by datetime-diff still using milliseconds and microseconds. Whereas date to-record doesn’t have them.
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 22 (20 by maintainers)
Commits related to this issue
- std dt datetime-diff: fix uninitialized field ref when borrowing (#10466) fixes #10455 @KAAtheWiseGit, I'm sorry, I didn't mean to block your first PR #10461, didn't see you had submitted it til... — committed to nushell/nushell by bobhy 9 months ago
- std dt datetime-diff: fix uninitialized field ref when borrowing (#10466) fixes #10455 @KAAtheWiseGit, I'm sorry, I didn't mean to block your first PR #10461, didn't see you had submitted it til... — committed to hardfau1t/nushell by bobhy 9 months ago
After looking at the source, I think the issue is that
borrow-secondcan accessmillisecondfield, before$resultgets those fields insidedatetime-diff.It seems it can be fixed either by giving
$resultthis fields earlier on, or removing them in favor of nanoseconds-only, asdate to-recorddoes. It seems a bit weird to me that these two commands have different record presentation.With
use std dt *. I was surprised to find out there were 11 various modules not exported by default.