mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #6503 from CausingBrick/issue-6495
date: fix date get timezone error while set utc time (#6495)
This commit is contained in:
commit
69b603bfe7
2 changed files with 12 additions and 4 deletions
|
@ -227,11 +227,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
Box::new(iter)
|
Box::new(iter)
|
||||||
}
|
}
|
||||||
DateSource::Human(relative_time) => {
|
DateSource::Human(relative_time) => {
|
||||||
// Get the current DateTime<FixedOffset> for things like "1 year ago"
|
// Double check the result is overflow or not of the current_time + relative_time
|
||||||
let current_time = DateTime::<FixedOffset>::from(Local::now());
|
|
||||||
// double check the result is overflow or not of the current_time + relative_time
|
|
||||||
// it may cause a panic of chrono::datetime::DateTime add
|
// 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) => {
|
Some(date) => {
|
||||||
let iter = std::iter::once(Ok(date));
|
let iter = std::iter::once(Ok(date));
|
||||||
Box::new(iter)
|
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]
|
#[test]
|
||||||
fn test_date_format_y() {
|
fn test_date_format_y() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue