add more granularity for into record with dates (#13650)

# 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 │
╰─────────────┴────────╯
```
This commit is contained in:
Darren Schroeder 2024-08-22 05:09:27 -05:00 committed by GitHub
parent 95b78eee25
commit ffddee5678
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<FixedOffset>, 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,