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

Most upvoted comments

After looking at the source, I think the issue is that borrow-second can access millisecond field, before $result gets those fields inside datetime-diff.

It seems it can be fixed either by giving $result this fields earlier on, or removing them in favor of nanoseconds-only, as date to-record does. 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.