update human-date-parser to 3.0 (#15426)

# Description

There's been much debate about whether to keep human-date-parser in
`into datetime`. We saw recently that a new version of the crate was
released that addressed some of our concerns. This PR is to make it
easier to test those fixes.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# 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.
-->
This commit is contained in:
Darren Schroeder 2025-04-01 07:18:11 -05:00 committed by GitHub
parent 9ba16dbdaf
commit a23e96c945
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 50 additions and 5 deletions

27
Cargo.lock generated
View File

@ -2386,12 +2386,13 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]] [[package]]
name = "human-date-parser" name = "human-date-parser"
version = "0.2.0" version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1116cf4debfe770c12168458321c4a8591b71c4c19f7100de07c84cf81701c63" checksum = "406f83c56de4b2c9183be52ae9a4fefa22c0e0c3d3d7ef80be26eaee11c7110e"
dependencies = [ dependencies = [
"chrono", "chrono",
"pest", "pest",
"pest_consume",
"pest_derive", "pest_derive",
"thiserror 1.0.69", "thiserror 1.0.69",
] ]
@ -4677,6 +4678,28 @@ dependencies = [
"ucd-trie", "ucd-trie",
] ]
[[package]]
name = "pest_consume"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79447402d15d18e7142e14c72f2e63fa3d155be1bc5b70b3ccbb610ac55f536b"
dependencies = [
"pest",
"pest_consume_macros",
"pest_derive",
]
[[package]]
name = "pest_consume_macros"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d8630a7a899cb344ec1c16ba0a6b24240029af34bdc0a21f84e411d7f793f29"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "pest_derive" name = "pest_derive"
version = "2.7.15" version = "2.7.15"

View File

@ -91,7 +91,7 @@ fancy-regex = "0.14"
filesize = "0.2" filesize = "0.2"
filetime = "0.2" filetime = "0.2"
heck = "0.5.0" heck = "0.5.0"
human-date-parser = "0.2.0" human-date-parser = "0.3.0"
indexmap = "2.8" indexmap = "2.8"
indicatif = "0.17" indicatif = "0.17"
interprocess = "2.2.0" interprocess = "2.2.0"

View File

@ -294,7 +294,7 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
match parse_date_from_string(&input_val, span) { match parse_date_from_string(&input_val, span) {
Ok(date) => return Value::date(date, span), Ok(date) => return Value::date(date, span),
Err(_) => { Err(_) => {
if let Ok(date) = from_human_time(&input_val) { if let Ok(date) = from_human_time(&input_val, Local::now().naive_local()) {
match date { match date {
ParseResult::Date(date) => { ParseResult::Date(date) => {
let time = Local::now().time(); let time = Local::now().time();
@ -307,7 +307,29 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
return Value::date(dt_fixed, span); return Value::date(dt_fixed, span);
} }
ParseResult::DateTime(date) => { ParseResult::DateTime(date) => {
return Value::date(date.fixed_offset(), span) let local_offset = *Local::now().offset();
let dt_fixed = match local_offset.from_local_datetime(&date) {
chrono::LocalResult::Single(dt) => dt,
chrono::LocalResult::Ambiguous(_, _) => {
return Value::error(
ShellError::DatetimeParseError {
msg: "Ambiguous datetime".to_string(),
span,
},
span,
);
}
chrono::LocalResult::None => {
return Value::error(
ShellError::DatetimeParseError {
msg: "Invalid datetime".to_string(),
span,
},
span,
);
}
};
return Value::date(dt_fixed, span);
} }
ParseResult::Time(time) => { ParseResult::Time(time) => {
let date = Local::now().date_naive(); let date = Local::now().date_naive();