summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/uu/date/src/date.rs6
-rw-r--r--tests/by-util/test_date.rs10
2 files changed, 12 insertions, 4 deletions
diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs
index 5d6e8fd22..02737dca2 100644
--- a/src/uu/date/src/date.rs
+++ b/src/uu/date/src/date.rs
@@ -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)
diff --git a/tests/by-util/test_date.rs b/tests/by-util/test_date.rs
index 16a01c655..13c340b07 100644
--- a/tests/by-util/test_date.rs
+++ b/tests/by-util/test_date.rs
@@ -142,6 +142,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!());