mirror of
https://github.com/nushell/nushell.git
synced 2025-01-25 15:51:28 +01:00
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:
parent
43905caa46
commit
d66a5398d1
@ -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::Hour => return Ok(x * 60 * 60 * 1000 * 1000 * 1000),
|
||||||
Unit::Day => return Ok(x * 24 * 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::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::Hour => return Ok(("hr", x)),
|
||||||
Unit::Day => return Ok(("day", x)),
|
Unit::Day => return Ok(("day", x)),
|
||||||
Unit::Week => return Ok(("wk", 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)),
|
_ => return Ok(("ns", 0)),
|
||||||
}
|
}
|
||||||
|
@ -526,35 +526,6 @@ fn convert_to_value(
|
|||||||
expr.span,
|
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(
|
Expr::Var(..) => Err(ShellError::OutsideSpannedLabeledError(
|
||||||
|
@ -335,14 +335,11 @@ fn duration_decimal_math_with_all_units() {
|
|||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
r#"
|
r#"
|
||||||
5dec + 3yr + 2month + 1wk + 3day + 8hr + 10min + 16sec + 121ms + 11us + 12ns
|
1wk + 3day + 8hr + 10min + 16sec + 121ms + 11us + 12ns
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(actual.out, "1wk 3day 8hr 10min 16sec 121ms 11µs 12ns");
|
||||||
actual.out,
|
|
||||||
"53yr 2month 1wk 3day 8hr 10min 16sec 121ms 11µs 12ns"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -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(),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2201,9 +2201,6 @@ pub fn parse_duration_bytes(bytes: &[u8], span: Span) -> Option<Expression> {
|
|||||||
(Unit::Hour, "HR", Some((Unit::Minute, 60))),
|
(Unit::Hour, "HR", Some((Unit::Minute, 60))),
|
||||||
(Unit::Day, "DAY", Some((Unit::Minute, 1440))),
|
(Unit::Day, "DAY", Some((Unit::Minute, 1440))),
|
||||||
(Unit::Week, "WK", Some((Unit::Day, 7))),
|
(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)) {
|
if let Some(unit) = unit_groups.iter().find(|&x| upper.ends_with(x.1)) {
|
||||||
let mut lhs = token;
|
let mut lhs = token;
|
||||||
|
@ -30,7 +30,4 @@ pub enum Unit {
|
|||||||
Hour,
|
Hour,
|
||||||
Day,
|
Day,
|
||||||
Week,
|
Week,
|
||||||
Month,
|
|
||||||
Year,
|
|
||||||
Decade,
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user