File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -708,7 +708,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
708708 } ;
709709
710710 let time_format = if time. is_some ( ) {
711- parse_time_style ( matches. get_one :: < String > ( "time-style" ) . map ( |s| s. as_str ( ) ) ) ?. to_string ( )
711+ parse_time_style (
712+ matches
713+ . get_one :: < String > ( options:: TIME_STYLE )
714+ . map ( |s| s. as_str ( ) ) ,
715+ ) ?
716+ . to_string ( )
712717 } else {
713718 "%Y-%m-%d %H:%M" . to_string ( )
714719 } ;
@@ -807,7 +812,10 @@ fn parse_time_style(s: Option<&str>) -> UResult<&str> {
807812 "full-iso" => Ok ( "%Y-%m-%d %H:%M:%S.%f %z" ) ,
808813 "long-iso" => Ok ( "%Y-%m-%d %H:%M" ) ,
809814 "iso" => Ok ( "%Y-%m-%d" ) ,
810- _ => Err ( DuError :: InvalidTimeStyleArg ( s. into ( ) ) . into ( ) ) ,
815+ _ => match s. strip_prefix ( '+' ) {
816+ Some ( s) => Ok ( s) ,
817+ _ => Err ( DuError :: InvalidTimeStyleArg ( s. into ( ) ) . into ( ) ) ,
818+ } ,
811819 } ,
812820 None => Ok ( "%Y-%m-%d %H:%M" ) ,
813821 }
Original file line number Diff line number Diff line change 77#[ cfg( not( windows) ) ]
88use regex:: Regex ;
99
10+ use rstest:: rstest;
1011use uutests:: at_and_ucmd;
1112use uutests:: new_ucmd;
1213#[ cfg( not( target_os = "windows" ) ) ]
@@ -1173,6 +1174,17 @@ fn test_invalid_time_style() {
11731174 . stdout_does_not_contain ( "du: invalid argument 'banana' for 'time style'" ) ;
11741175}
11751176
1177+ #[ rstest]
1178+ #[ case:: full_iso( "+%Y-%m-%d %H:%M:%S.%f %z" ) ]
1179+ #[ case:: long_iso( "+%Y-%m-%d %H:%M" ) ]
1180+ #[ case:: iso( "+%Y-%m-%d" ) ]
1181+ #[ case:: seconds( "+%S" ) ]
1182+ fn test_valid_time_style ( #[ case] input : & str ) {
1183+ new_ucmd ! ( )
1184+ . args ( & [ "--time" , "--time-style" , input] )
1185+ . succeeds ( ) ;
1186+ }
1187+
11761188#[ test]
11771189fn test_human_size ( ) {
11781190 use std:: fs:: File ;
You can’t perform that action at this time.
0 commit comments