From c0b99b713123c1a9251439497d8f6850d2d18784 Mon Sep 17 00:00:00 2001 From: Reilly Wood <26268125+rgwood@users.noreply.github.com> Date: Tue, 10 May 2022 11:15:28 -0700 Subject: [PATCH] Enable converting dates to ints (#5489) --- crates/nu-command/src/conversions/into/int.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/nu-command/src/conversions/into/int.rs b/crates/nu-command/src/conversions/into/int.rs index e39d660e39..a1ff6fffb5 100644 --- a/crates/nu-command/src/conversions/into/int.rs +++ b/crates/nu-command/src/conversions/into/int.rs @@ -85,6 +85,11 @@ impl Command for SubCommand { span: Span::test_data(), }), }, + Example { + description: "Convert date to integer (Unix timestamp)", + example: "2022-02-02 | into int", + result: Some(Value::test_int(1643760000)), + }, Example { description: "Convert to integer from binary", example: "'1101' | into int -r 2", @@ -181,6 +186,10 @@ pub fn action(input: &Value, span: Span, radix: u32) -> Value { Value::Int { val: 0, span } } } + Value::Date { val, .. } => Value::Int { + val: val.timestamp(), + span, + }, _ => Value::Error { error: ShellError::UnsupportedInput("'into int' for unsupported type".into(), span), },