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
@@ -410,6 +411,31 @@ fn test_date_string_human() {
410411 }
411412}
412413
414+ #[ test]
415+ fn test_negative_offset ( ) {
416+ let data_formats = vec ! [
417+ ( "-1 hour" , Duration :: hours( 1 ) ) ,
418+ ( "-1 hours" , Duration :: hours( 1 ) ) ,
419+ ( "-1 day" , Duration :: days( 1 ) ) ,
420+ ( "-2 weeks" , Duration :: weeks( 2 ) ) ,
421+ ] ;
422+ for ( date_format, offset) in data_formats {
423+ new_ucmd ! ( )
424+ . arg ( "-d" )
425+ . arg ( date_format)
426+ . arg ( "--rfc-3339=seconds" )
427+ . succeeds ( )
428+ . stdout_str_check ( |out| {
429+ let date = DateTime :: parse_from_rfc3339 ( out. trim ( ) ) . unwrap ( ) ;
430+
431+ // Is the resulting date roughly what is expected?
432+ let expected_date = Utc :: now ( ) - offset;
433+ date > expected_date - Duration :: minutes ( 10 )
434+ && date < expected_date + Duration :: minutes ( 10 )
435+ } ) ;
436+ }
437+ }
438+
413439#[ test]
414440fn test_invalid_date_string ( ) {
415441 new_ucmd ! ( )
You can’t perform that action at this time.
0 commit comments