nushell/crates/nu-std/std
Bob Hyman bc437da5c7
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 till I got around to submitting this. If
you want to incoporate useful ideas from this PR into yours, I do not
mind deferring to you.


# Description
Changes made in `datetime-diff`:
* Initialize millisecond and microsecond fields in `$current`, to fix
the error when borrow needs to refer to them.
* Fix `borrow_nanoseconds` to borrow from seconds, not from (unused)
microseconds.
* Added error check to insist that first argument is >= second argument.
`datetime-diff` doesn't represent negative durations correctly (it tries
to borrow out of the year, resulting in negative year and positive all
other fields). We don't currently have a use case requiring negative
durations.
* Add comments so help is a bit clearer (I was surprised that the first
argument, named `$from` was actually supposed to be the *later*
datetime. The order of arguments is reasonable (reminiscent of <later>
<minus> <earlier>), so I just changed the param name to match its
purpose.

Changes made in `pretty-print-duration`:
* changed type of argument from `duration` to `record`. (it's not clear
why Nu was not complaining about this!)
* changed test for skipping a clause from `> 0` to `!= 0`. Even though
`datetime-diff` won't present a negative field in the record, user might
call `pretty-print-duration` with one, might as well handle it. (but I
think `hour:-2` will be rendered as `-2hr`, not `-2hrs`...).
* added help and an example.

# User-Facing Changes
none requiring code changes.

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
- 
- # After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-09-24 10:53:56 +02:00
..
assert.nu Implement annotations support in test runner (#9406) 2023-07-02 10:41:33 +02:00
dirs.nu remove let-env, focus on mutating $env (#9574) 2023-07-01 07:57:51 +12:00
dt.nu std dt datetime-diff: fix uninitialized field ref when borrowing (#10466) 2023-09-24 10:53:56 +02:00
formats.nu add 'from ndjson' into standard library (#10283) 2023-09-11 14:59:07 +02:00
help.nu differentiating between --x and --x: bool (#10456) 2023-09-23 10:20:48 +02:00
input.nu Command to get individual keys (#9453) 2023-07-03 10:23:44 -05:00
iter.nu Add zip-into-record to std iter (#9395) 2023-06-10 20:15:30 +02:00
log.nu change LOG_FORMAT to NU_LOG_FORMAT in nu-std library (#10254) 2023-09-06 10:17:14 -07:00
math.nu move math constants to standard library (#9678) 2023-09-05 19:32:31 +02:00
mod.nu fix public boolean switches in the standard library (#10477) 2023-09-23 06:40:28 -05:00
testing.nu fix the pretty printing of failing tests in std (#10373) 2023-09-14 20:11:08 +02:00
xml.nu Improve type hovers (#9515) 2023-06-29 05:19:48 +12:00