From ffddee5678367c6d8ddc1113460ad6009a4142bb Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Thu, 22 Aug 2024 05:09:27 -0500 Subject: [PATCH] add more granularity for into record with dates (#13650) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description This PR adds a little more granularity when using `into record` with dates. ### Before ```nushell ❯ date now | into record ╭──────────┬────────╮ │ year │ 2024 │ │ month │ 8 │ │ day │ 19 │ │ hour │ 18 │ │ minute │ 31 │ │ second │ 27 │ │ timezone │ -05:00 │ ╰──────────┴────────╯ ``` ### After ```nushell ❯ date now | into record ╭─────────────┬────────╮ │ year │ 2024 │ │ month │ 8 │ │ day │ 19 │ │ hour │ 18 │ │ minute │ 30 │ │ second │ 51 │ │ millisecond │ 928 │ │ microsecond │ 980 │ │ nanosecond │ 0 │ │ timezone │ -05:00 │ ╰─────────────┴────────╯ ``` --- crates/nu-command/src/conversions/into/record.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/nu-command/src/conversions/into/record.rs b/crates/nu-command/src/conversions/into/record.rs index 6290739060..445d81cb86 100644 --- a/crates/nu-command/src/conversions/into/record.rs +++ b/crates/nu-command/src/conversions/into/record.rs @@ -93,6 +93,9 @@ impl Command for SubCommand { "hour" => Value::test_int(22), "minute" => Value::test_int(10), "second" => Value::test_int(57), + "millisecond" => Value::test_int(0), + "microsecond" => Value::test_int(0), + "nanosecond" => Value::test_int(0), "timezone" => Value::test_string("+02:00"), })), }, @@ -187,6 +190,9 @@ fn parse_date_into_record(date: DateTime, span: Span) -> Value { "hour" => Value::int(date.hour() as i64, span), "minute" => Value::int(date.minute() as i64, span), "second" => Value::int(date.second() as i64, span), + "millisecond" => Value::int(date.timestamp_subsec_millis() as i64, span), + "microsecond" => Value::int((date.nanosecond() / 1_000 % 1_000) as i64, span), + "nanosecond" => Value::int((date.nanosecond() % 1_000) as i64, span), "timezone" => Value::string(date.offset().to_string(), span), }, span,