mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 14:52:41 +00:00
date: fix date get timezone error while set utc time (#6495)
This commit is contained in:
parent
11e8476456
commit
e4ec608781
2 changed files with 12 additions and 4 deletions
|
@ -227,11 +227,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
Box::new(iter)
|
||||
}
|
||||
DateSource::Human(relative_time) => {
|
||||
// Get the current DateTime<FixedOffset> for things like "1 year ago"
|
||||
let current_time = DateTime::<FixedOffset>::from(Local::now());
|
||||
// double check the result is overflow or not of the current_time + relative_time
|
||||
// Double check the result is overflow or not of the current_time + relative_time
|
||||
// it may cause a panic of chrono::datetime::DateTime add
|
||||
match current_time.checked_add_signed(relative_time) {
|
||||
match now.checked_add_signed(relative_time) {
|
||||
Some(date) => {
|
||||
let iter = std::iter::once(Ok(date));
|
||||
Box::new(iter)
|
||||
|
|
|
@ -141,6 +141,16 @@ fn test_date_utc() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_date_utc_issue_6495() {
|
||||
new_ucmd!()
|
||||
.arg("-u")
|
||||
.arg("-d")
|
||||
.arg("@0")
|
||||
.succeeds()
|
||||
.stdout_is("Thu Jan 1 00:00:00 1970\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_date_format_y() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
|
Loading…
Reference in a new issue