File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -318,6 +318,7 @@ pub fn uu_app() -> Command {
318318 . short ( 'd' )
319319 . long ( OPT_DATE )
320320 . value_name ( "STRING" )
321+ . allow_hyphen_values ( true )
321322 . help ( "display time described by STRING, not 'now'" ) ,
322323 )
323324 . arg (
Original file line number Diff line number Diff line change 1+ use chrono:: { DateTime , Duration , Utc } ;
12// This file is part of the uutils coreutils package.
23//
34// For the full copyright and license information, please view the LICENSE
@@ -412,6 +413,31 @@ fn test_date_string_human() {
412413 }
413414}
414415
416+ #[ test]
417+ fn test_negative_offset ( ) {
418+ let data_formats = vec ! [
419+ ( "-1 hour" , Duration :: hours( 1 ) ) ,
420+ ( "-1 hours" , Duration :: hours( 1 ) ) ,
421+ ( "-1 day" , Duration :: days( 1 ) ) ,
422+ ( "-2 weeks" , Duration :: weeks( 2 ) ) ,
423+ ] ;
424+ for ( date_format, offset) in data_formats {
425+ new_ucmd ! ( )
426+ . arg ( "-d" )
427+ . arg ( date_format)
428+ . arg ( "--rfc-3339=seconds" )
429+ . succeeds ( )
430+ . stdout_str_check ( |out| {
431+ let date = DateTime :: parse_from_rfc3339 ( out. trim ( ) ) . unwrap ( ) ;
432+
433+ // Is the resulting date roughly what is expected?
434+ let expected_date = Utc :: now ( ) - offset;
435+ date > expected_date - Duration :: minutes ( 10 )
436+ && date < expected_date + Duration :: minutes ( 10 )
437+ } ) ;
438+ }
439+ }
440+
415441#[ test]
416442fn test_invalid_date_string ( ) {
417443 new_ucmd ! ( )
You can’t perform that action at this time.
0 commit comments