nushell/crates/nu-protocol/src
Loïc Riegel 08940ba4f8
bugfix: wrong display of human readable string (#15522)
I think after that we can close  #14790

# Description
So the issue was the tiny time delta between the moment the "date
form-human" command is executed, and the moment the value gets
displayed, using chrono_humanize.

When in inputing "in 30 seconds", we currently get:
```
[crates\nu-protocol\src\value\mod.rs:950:21] HumanTime::from(*val) = HumanTime(
    TimeDelta {
        secs: 29,
        nanos: 992402700,
    },
)```
And with "now":
```
crates\nu-protocol\src\value\mod.rs:950:21] HumanTime::from(*val) =
HumanTime(
    TimeDelta {
        secs: -1,
        nanos: 993393200,
    },
)
```

My solution is to round this timedelta to seconds and pass this to chrono_humanize.
Example: instead of passing (-1s + 993393200ns), we pass 0s.
Example: instead of passing (29s + 992402700ns), we pass 30s


# User-Facing Changes
Before 🔴 
```nushell
~> "in 3 days" | date from-human
Fri, 11 Apr 2025 09:06:36 +0200 (in 2 days)
~> "in 30 seconds" | date from-human
Tue, 8 Apr 2025 09:07:09 +0200 (in 29 seconds)
```

After those changes 🟢 
```nushell
~> "in 3 days" | date from-human
Fri, 11 Apr 2025 09:03:47 +0200 (in 3 days)
~> "in 30 seconds" | date from-human
Tue, 8 Apr 2025 09:04:28 +0200 (in 30 seconds)
```

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu  # or use an `env_change` hook to activate it automatically
> toolkit check pr
> ```
-->

# 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. -->
2025-04-08 06:29:16 -05:00
..
ast preserve variable capture spans in blocks (#15334) 2025-03-20 14:20:28 -04:00
config Add filesize.show_unit config option (#15276) 2025-03-09 17:34:55 -05:00
debugger Custom command attributes (#14906) 2025-02-11 06:34:51 -06:00
engine Fix future clippy lints (#15519) 2025-04-08 08:51:12 +08:00
errors fix(parser): skip eval_const if parsing errors detected to avoid panic (#15364) 2025-03-26 15:02:26 +01:00
ir fix: clippy warning of rust 1.8.4 (#14984) 2025-02-02 07:56:54 -06:00
pipeline Remove nu-glob's dependency on nu-protocol (#15349) 2025-03-20 17:32:41 +01:00
plugin Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
process Jobs (#14883) 2025-02-25 12:09:52 -05:00
value bugfix: wrong display of human readable string (#15522) 2025-04-08 06:29:16 -05:00
alias.rs Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
did_you_mean.rs Improve case insensitivity consistency (#10884) 2023-11-08 23:58:54 +01:00
eval_base.rs Rework operator type errors (#14429) 2025-02-12 20:03:40 -08:00
eval_const.rs Reminder comment to update doc when adding $nu constants (#15481) 2025-04-07 00:38:17 -04:00
example.rs Overhaul the plugin cache file with a new msgpack+brotli format (#12579) 2024-04-21 07:36:26 -05:00
id.rs Jobs (#14883) 2025-02-25 12:09:52 -05:00
lev_distance.rs Fix clippy (#15489) 2025-04-06 09:49:28 +08:00
lib.rs Start to Add WASM Support Again (#14418) 2024-11-30 07:57:11 -06:00
module.rs refactor(parser): use var_id for most constants in ResolvedImportPattern (#14920) 2025-01-26 15:43:34 +02:00
parser_path.rs Replace raw usize IDs with new types (#13832) 2024-09-30 13:20:15 +02:00
signature.rs add attr category @category to custom command attributes (#15137) 2025-02-18 15:35:52 -06:00
span.rs Parse XML documents with DTDs by default, and add --disallow-dtd flag (#15272) 2025-03-12 08:09:55 -05:00
syntax_shape.rs Remove unsued types (#14916) 2025-01-26 12:30:58 +08:00
ty.rs Rename user-facing 'date' to 'datetime' (#15264) 2025-03-21 13:36:21 -04:00