mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
Merge pull request #7548 from lewisboon/bugfix/date-negative-offset
date: allow negative date offsets
This commit is contained in:
commit
d33d731804
2 changed files with 27 additions and 0 deletions
|
@ -318,6 +318,7 @@ pub fn uu_app() -> Command {
|
||||||
.short('d')
|
.short('d')
|
||||||
.long(OPT_DATE)
|
.long(OPT_DATE)
|
||||||
.value_name("STRING")
|
.value_name("STRING")
|
||||||
|
.allow_hyphen_values(true)
|
||||||
.help("display time described by STRING, not 'now'"),
|
.help("display time described by STRING, not 'now'"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use chrono::{DateTime, Duration, Utc};
|
||||||
// This file is part of the uutils coreutils package.
|
// This file is part of the uutils coreutils package.
|
||||||
//
|
//
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
|
@ -412,6 +413,31 @@ fn test_date_string_human() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_negative_offset() {
|
||||||
|
let data_formats = vec![
|
||||||
|
("-1 hour", Duration::hours(1)),
|
||||||
|
("-1 hours", Duration::hours(1)),
|
||||||
|
("-1 day", Duration::days(1)),
|
||||||
|
("-2 weeks", Duration::weeks(2)),
|
||||||
|
];
|
||||||
|
for (date_format, offset) in data_formats {
|
||||||
|
new_ucmd!()
|
||||||
|
.arg("-d")
|
||||||
|
.arg(date_format)
|
||||||
|
.arg("--rfc-3339=seconds")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_str_check(|out| {
|
||||||
|
let date = DateTime::parse_from_rfc3339(out.trim()).unwrap();
|
||||||
|
|
||||||
|
// Is the resulting date roughly what is expected?
|
||||||
|
let expected_date = Utc::now() - offset;
|
||||||
|
date > expected_date - Duration::minutes(10)
|
||||||
|
&& date < expected_date + Duration::minutes(10)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_invalid_date_string() {
|
fn test_invalid_date_string() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue