diff --git a/crates/nu-data/src/value.rs b/crates/nu-data/src/value.rs index 70b4e051a2..d4764ea43c 100644 --- a/crates/nu-data/src/value.rs +++ b/crates/nu-data/src/value.rs @@ -477,11 +477,7 @@ pub fn compute_values( } let y = y.as_bigint_and_exponent(); - let z = y.0.to_i64(); - match z { - Some(z) => Ok(x / z), - None => Err((left.type_name(), right.type_name())), - } + Ok(x / y.0) } _ => Err((left.type_name(), right.type_name())), }?; diff --git a/crates/nu-engine/src/command_args.rs b/crates/nu-engine/src/command_args.rs index cfc7325454..6f34ee37cc 100644 --- a/crates/nu-engine/src/command_args.rs +++ b/crates/nu-engine/src/command_args.rs @@ -76,15 +76,6 @@ impl CommandArgs { Ok((f(&evaluated_args.args)?, evaluated_args.input)) } - - // pub fn process<'de, T: Deserialize<'de>>(self) -> Result<(T, InputStream), ShellError> { - // let args = self.evaluate_once()?; - // let call_info = args.call_info.clone(); - - // let mut deserializer = ConfigDeserializer::from_call_info(call_info); - - // Ok((T::deserialize(&mut deserializer)?, args.input)) - // } } pub struct EvaluatedCommandArgs { diff --git a/crates/nu-protocol/src/hir.rs b/crates/nu-protocol/src/hir.rs index da5f6242d3..7ebf07f2b0 100644 --- a/crates/nu-protocol/src/hir.rs +++ b/crates/nu-protocol/src/hir.rs @@ -587,21 +587,21 @@ impl Unit { Unit::Tebibyte => filesize(size * 1024 * 1024 * 1024 * 1024), Unit::Pebibyte => filesize(size * 1024 * 1024 * 1024 * 1024 * 1024), - Unit::Nanosecond => duration(size.to_i64().expect("Conversion should never fail.")), + Unit::Nanosecond => duration(size.to_bigint().expect("Conversion should never fail.")), Unit::Microsecond => { - duration(size.to_i64().expect("Conversion should never fail.") * 1000) + duration(size.to_bigint().expect("Conversion should never fail.") * 1000) } Unit::Millisecond => { - duration(size.to_i64().expect("Conversion should never fail.") * 1000 * 1000) - } - Unit::Second => { - duration(size.to_i64().expect("Conversion should never fail.") * 1000 * 1000 * 1000) + duration(size.to_bigint().expect("Conversion should never fail.") * 1000 * 1000) } + Unit::Second => duration( + size.to_bigint().expect("Conversion should never fail.") * 1000 * 1000 * 1000, + ), Unit::Minute => duration( - size.to_i64().expect("Conversion should never fail.") * 60 * 1000 * 1000 * 1000, + size.to_bigint().expect("Conversion should never fail.") * 60 * 1000 * 1000 * 1000, ), Unit::Hour => duration( - size.to_i64().expect("Conversion should never fail.") + size.to_bigint().expect("Conversion should never fail.") * 60 * 60 * 1000 @@ -609,7 +609,7 @@ impl Unit { * 1000, ), Unit::Day => duration( - size.to_i64().expect("Conversion should never fail.") + size.to_bigint().expect("Conversion should never fail.") * 24 * 60 * 60 @@ -618,7 +618,7 @@ impl Unit { * 1000, ), Unit::Week => duration( - size.to_i64().expect("Conversion should never fail.") + size.to_bigint().expect("Conversion should never fail.") * 7 * 24 * 60 diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index 227e11999d..ce370d9347 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -898,6 +898,31 @@ fn table_with_commas() { assert_eq!(actual.out, "141"); } +#[test] +fn duration_overflow() { + let actual = nu!( + cwd: ".", pipeline( + r#" + ls | get modified | each { $it + 10000000000000000day } + "#) + ); + + assert!(actual.err.contains("Duration overflow")); +} + +#[test] +fn date_and_duration_overflow() { + let actual = nu!( + cwd: ".", pipeline( + r#" + ls | get modified | each { $it + 1000000000day } + "#) + ); + + // assert_eq!(actual.err, "overflow"); + assert!(actual.err.contains("Duration and date addition overflow")); +} + mod parse { use nu_test_support::nu;