From 07ad24ab974f50c6e040703a26fe1397630fce6e Mon Sep 17 00:00:00 2001 From: Douglas <32344964+NotTheDr01ds@users.noreply.github.com> Date: Mon, 11 Nov 2024 07:01:39 -0500 Subject: [PATCH] Fix ignored `into datetime` test (#14302) # Description Fixes test which was ignored in #14297. Also fixes related example. Tests now use local timezone to match actual result. More discussion in #14266 # User-Facing Changes Tests-only # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :green_circle: `toolkit test` - :green_circle: `toolkit test stdlib` # After Submitting N/A --- .../src/conversions/into/datetime.rs | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/crates/nu-command/src/conversions/into/datetime.rs b/crates/nu-command/src/conversions/into/datetime.rs index dcb37291af..0f6580cbc8 100644 --- a/crates/nu-command/src/conversions/into/datetime.rs +++ b/crates/nu-command/src/conversions/into/datetime.rs @@ -185,11 +185,13 @@ impl Command for SubCommand { example: "'16.11.1984 8:00 am' | into datetime --format '%d.%m.%Y %H:%M %P'", #[allow(clippy::inconsistent_digit_grouping)] result: Some(Value::date( - DateTime::from_naive_utc_and_offset( - NaiveDateTime::parse_from_str("16.11.1984 8:00 am", "%d.%m.%Y %H:%M %P") - .expect("date calculation should not fail in test"), - *Local::now().offset(), - ), + Local + .from_local_datetime( + &NaiveDateTime::parse_from_str("16.11.1984 8:00 am", "%d.%m.%Y %H:%M %P") + .expect("date calculation should not fail in test"), + ) + .unwrap() + .with_timezone(Local::now().offset()), Span::test_data(), )), }, @@ -524,12 +526,16 @@ mod tests { }; let actual = action(&date_str, &args, Span::test_data()); let expected = Value::date( - DateTime::from_naive_utc_and_offset( - NaiveDateTime::parse_from_str("16.11.1984 8:00 am", "%d.%m.%Y %H:%M %P").unwrap(), - *Local::now().offset(), - ), + Local + .from_local_datetime( + &NaiveDateTime::parse_from_str("16.11.1984 8:00 am", "%d.%m.%Y %H:%M %P") + .unwrap(), + ) + .unwrap() + .with_timezone(Local::now().offset()), Span::test_data(), ); + assert_eq!(actual, expected) }