Remove month and year duration constants (#6613)

remove month/year/decade durations for parsing and units, but leave the humanized output for viewing
This commit is contained in:
JT 2022-09-26 09:55:13 +13:00 committed by GitHub
parent 43905caa46
commit d66a5398d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 2 additions and 82 deletions

View File

@ -315,9 +315,6 @@ fn string_to_duration(s: &str, span: Span, value_span: Span) -> Result<i64, Shel
Unit::Hour => return Ok(x * 60 * 60 * 1000 * 1000 * 1000),
Unit::Day => return Ok(x * 24 * 60 * 60 * 1000 * 1000 * 1000),
Unit::Week => return Ok(x * 7 * 24 * 60 * 60 * 1000 * 1000 * 1000),
Unit::Month => return Ok(x * 30 * 24 * 60 * 60 * 1000 * 1000 * 1000), //30 days to a month
Unit::Year => return Ok(x * 365 * 24 * 60 * 60 * 1000 * 1000 * 1000), //365 days to a year
Unit::Decade => return Ok(x * 10 * 365 * 24 * 60 * 60 * 1000 * 1000 * 1000), //365 days to a year
_ => {}
}
}
@ -353,9 +350,6 @@ fn string_to_unit_duration(
Unit::Hour => return Ok(("hr", x)),
Unit::Day => return Ok(("day", x)),
Unit::Week => return Ok(("wk", x)),
Unit::Month => return Ok(("month", x)), //30 days to a month
Unit::Year => return Ok(("yr", x)), //365 days to a year
Unit::Decade => return Ok(("dec", x)), //365 days to a year
_ => return Ok(("ns", 0)),
}

View File

@ -526,35 +526,6 @@ fn convert_to_value(
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(

View File

@ -335,14 +335,11 @@ fn duration_decimal_math_with_all_units() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
5dec + 3yr + 2month + 1wk + 3day + 8hr + 10min + 16sec + 121ms + 11us + 12ns
1wk + 3day + 8hr + 10min + 16sec + 121ms + 11us + 12ns
"#
));
assert_eq!(
actual.out,
"53yr 2month 1wk 3day 8hr 10min 16sec 121ms 11µs 12ns"
);
assert_eq!(actual.out, "1wk 3day 8hr 10min 16sec 121ms 11µs 12ns");
}
#[test]

View File

@ -1570,41 +1570,5 @@ fn compute(size: i64, unit: Unit, span: Span) -> Value {
),
},
},
Unit::Month => match size.checked_mul(1000 * 1000 * 1000 * 60 * 60 * 24 * 30) {
Some(val) => Value::Duration { val, span },
None => Value::Error {
error: ShellError::GenericError(
"month duration too large".into(),
"month duration too large".into(),
Some(span),
None,
Vec::new(),
),
},
},
Unit::Year => match size.checked_mul(1000 * 1000 * 1000 * 60 * 60 * 24 * 365) {
Some(val) => Value::Duration { val, span },
None => Value::Error {
error: ShellError::GenericError(
"year duration too large".into(),
"year duration too large".into(),
Some(span),
None,
Vec::new(),
),
},
},
Unit::Decade => match size.checked_mul(1000 * 1000 * 1000 * 60 * 60 * 24 * 365 * 10) {
Some(val) => Value::Duration { val, span },
None => Value::Error {
error: ShellError::GenericError(
"decade duration too large".into(),
"decade duration too large".into(),
Some(span),
None,
Vec::new(),
),
},
},
}
}

View File

@ -2201,9 +2201,6 @@ pub fn parse_duration_bytes(bytes: &[u8], span: Span) -> Option<Expression> {
(Unit::Hour, "HR", Some((Unit::Minute, 60))),
(Unit::Day, "DAY", Some((Unit::Minute, 1440))),
(Unit::Week, "WK", Some((Unit::Day, 7))),
(Unit::Month, "MONTH", Some((Unit::Day, 30))), //30 day month
(Unit::Year, "YR", Some((Unit::Day, 365))), //365 day year
(Unit::Decade, "DEC", Some((Unit::Year, 10))), //365 day years
];
if let Some(unit) = unit_groups.iter().find(|&x| upper.ends_with(x.1)) {
let mut lhs = token;

View File

@ -30,7 +30,4 @@ pub enum Unit {
Hour,
Day,
Week,
Month,
Year,
Decade,
}