mirror of
https://github.com/nushell/nushell.git
synced 2025-03-13 15:08:43 +01:00
Merge 47d9ae9015
into 0f6996b70d
This commit is contained in:
commit
454446a0dd
@ -15,6 +15,7 @@ impl Command for SubCommand {
|
|||||||
Signature::build("into duration")
|
Signature::build("into duration")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![
|
||||||
(Type::Int, Type::Duration),
|
(Type::Int, Type::Duration),
|
||||||
|
(Type::Float, Type::Duration),
|
||||||
(Type::String, Type::Duration),
|
(Type::String, Type::Duration),
|
||||||
(Type::Duration, Type::Duration),
|
(Type::Duration, Type::Duration),
|
||||||
(Type::table(), Type::table()),
|
(Type::table(), Type::table()),
|
||||||
@ -109,6 +110,11 @@ impl Command for SubCommand {
|
|||||||
example: "1_234 | into duration --unit ms",
|
example: "1_234 | into duration --unit ms",
|
||||||
result: Some(Value::test_duration(1_234 * 1_000_000)),
|
result: Some(Value::test_duration(1_234 * 1_000_000)),
|
||||||
},
|
},
|
||||||
|
Example {
|
||||||
|
description: "Convert a floating point number of an arbitrary unit to duration",
|
||||||
|
example: "1.234 | into duration --unit sec",
|
||||||
|
result: Some(Value::test_duration(1_234 * 1_000_000)),
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,6 +246,13 @@ fn action(input: &Value, unit: &str, span: Span) -> Value {
|
|||||||
Ok(val) => Value::duration(val, span),
|
Ok(val) => Value::duration(val, span),
|
||||||
Err(error) => Value::error(error, span),
|
Err(error) => Value::error(error, span),
|
||||||
},
|
},
|
||||||
|
Value::Float { val, .. } => {
|
||||||
|
let val_str = format!("{}{}", val, unit);
|
||||||
|
match compound_to_duration(&val_str, value_span) {
|
||||||
|
Ok(val) => Value::duration(val, span),
|
||||||
|
Err(error) => Value::error(error, span),
|
||||||
|
}
|
||||||
|
}
|
||||||
Value::Int { val, .. } => {
|
Value::Int { val, .. } => {
|
||||||
let ns = match unit {
|
let ns = match unit {
|
||||||
"ns" => 1,
|
"ns" => 1,
|
||||||
|
Loading…
Reference in New Issue
Block a user