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

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
This commit is contained in:
Douglas 2024-11-11 07:01:39 -05:00 committed by GitHub
parent 55db643048
commit 07ad24ab97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)
}