mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 00:13:21 +01:00
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:
parent
95b78eee25
commit
ffddee5678
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user