mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
expand durations to include month, year, decade (#6123)
* expand durations to include month, year, decade * remove commented out fn * oops, found more debug comments * tweaked tests for the new way, borrowed heavily from chrono-humanize-rs * clippy * grammar
This commit is contained in:
@ -442,6 +442,14 @@ fn convert_to_value(
|
||||
val: size * 1000 * 1000 * 1000 * 1000 * 1000,
|
||||
span,
|
||||
}),
|
||||
Unit::Exabyte => Ok(Value::Filesize {
|
||||
val: size * 1000 * 1000 * 1000 * 1000 * 1000 * 1000,
|
||||
span,
|
||||
}),
|
||||
Unit::Zettabyte => Ok(Value::Filesize {
|
||||
val: size * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000,
|
||||
span,
|
||||
}),
|
||||
|
||||
Unit::Kibibyte => Ok(Value::Filesize {
|
||||
val: size * 1024,
|
||||
@ -463,6 +471,14 @@ fn convert_to_value(
|
||||
val: size * 1024 * 1024 * 1024 * 1024 * 1024,
|
||||
span,
|
||||
}),
|
||||
Unit::Exbibyte => Ok(Value::Filesize {
|
||||
val: size * 1024 * 1024 * 1024 * 1024 * 1024 * 1024,
|
||||
span,
|
||||
}),
|
||||
Unit::Zebibyte => Ok(Value::Filesize {
|
||||
val: size * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024,
|
||||
span,
|
||||
}),
|
||||
|
||||
Unit::Nanosecond => Ok(Value::Duration { val: size, span }),
|
||||
Unit::Microsecond => Ok(Value::Duration {
|
||||
@ -489,8 +505,8 @@ fn convert_to_value(
|
||||
Some(val) => Ok(Value::Duration { val, span }),
|
||||
None => Err(ShellError::OutsideSpannedLabeledError(
|
||||
original_text.to_string(),
|
||||
"duration too large".into(),
|
||||
"duration too large".into(),
|
||||
"day duration too large".into(),
|
||||
"day duration too large".into(),
|
||||
expr.span,
|
||||
)),
|
||||
},
|
||||
@ -499,11 +515,40 @@ fn convert_to_value(
|
||||
Some(val) => Ok(Value::Duration { val, span }),
|
||||
None => Err(ShellError::OutsideSpannedLabeledError(
|
||||
original_text.to_string(),
|
||||
"duration too large".into(),
|
||||
"duration too large".into(),
|
||||
"week duration too large".into(),
|
||||
"week duration too large".into(),
|
||||
expr.span,
|
||||
)),
|
||||
},
|
||||
Unit::Month => match size.checked_mul(1000 * 1000 * 1000 * 60 * 60 * 24 * 30) {
|
||||
Some(val) => Ok(Value::Duration { val, span }),
|
||||
None => Err(ShellError::OutsideSpannedLabeledError(
|
||||
original_text.to_string(),
|
||||
"month duration too large".into(),
|
||||
"month duration too large".into(),
|
||||
expr.span,
|
||||
)),
|
||||
},
|
||||
Unit::Year => match size.checked_mul(1000 * 1000 * 1000 * 60 * 60 * 24 * 365) {
|
||||
Some(val) => Ok(Value::Duration { val, span }),
|
||||
None => Err(ShellError::OutsideSpannedLabeledError(
|
||||
original_text.to_string(),
|
||||
"year duration too large".into(),
|
||||
"year duration too large".into(),
|
||||
expr.span,
|
||||
)),
|
||||
},
|
||||
Unit::Decade => {
|
||||
match size.checked_mul(1000 * 1000 * 1000 * 60 * 60 * 24 * 365 * 10) {
|
||||
Some(val) => Ok(Value::Duration { val, span }),
|
||||
None => Err(ShellError::OutsideSpannedLabeledError(
|
||||
original_text.to_string(),
|
||||
"decade duration too large".into(),
|
||||
"decade duration too large".into(),
|
||||
expr.span,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Expr::Var(..) => Err(ShellError::OutsideSpannedLabeledError(
|
||||
|
Reference in New Issue
Block a user