@@ -60,7 +60,7 @@ use uucore::line_ending::LineEnding;
6060use uucore:: translate;
6161
6262use uucore:: quoting_style:: { QuotingStyle , locale_aware_escape_dir_name, locale_aware_escape_name} ;
63- use uucore:: time:: { FormatSystemTimeFallback , format_system_time} ;
63+ use uucore:: time:: { FormatSystemTimeFallback , format , format_system_time} ;
6464use uucore:: {
6565 display:: Quotable ,
6666 error:: { UError , UResult , set_exit_code} ,
@@ -251,16 +251,8 @@ enum Files {
251251}
252252
253253fn parse_time_style ( options : & clap:: ArgMatches ) -> Result < ( String , Option < String > ) , LsError > {
254- const TIME_STYLES : [ ( & str , ( & str , Option < & str > ) ) ; 4 ] = [
255- ( "full-iso" , ( "%Y-%m-%d %H:%M:%S.%f %z" , None ) ) ,
256- ( "long-iso" , ( "%Y-%m-%d %H:%M" , None ) ) ,
257- ( "iso" , ( "%m-%d %H:%M" , Some ( "%Y-%m-%d " ) ) ) ,
258- // TODO: Using correct locale string is not implemented.
259- ( "locale" , ( "%b %e %H:%M" , Some ( "%b %e %Y" ) ) ) ,
260- ] ;
261- // A map from a time-style parameter to a length-2 tuple of formats:
262- // the first one is used for recent dates, the second one for older ones (optional).
263- let time_styles = HashMap :: from ( TIME_STYLES ) ;
254+ // TODO: Using correct locale string is not implemented.
255+ const LOCALE_FORMAT : ( & str , Option < & str > ) = ( "%b %e %H:%M" , Some ( "%b %e %Y" ) ) ;
264256
265257 // Convert time_styles references to owned String/option.
266258 fn ok ( ( recent, older) : ( & str , Option < & str > ) ) -> Result < ( String , Option < String > ) , LsError > {
@@ -278,7 +270,7 @@ fn parse_time_style(options: &clap::ArgMatches) -> Result<(String, Option<String
278270 && options. indices_of ( options:: FULL_TIME ) . unwrap ( ) . next_back ( )
279271 > options. indices_of ( options:: TIME_STYLE ) . unwrap ( ) . next_back ( )
280272 {
281- ok ( time_styles [ "full-iso" ] )
273+ ok ( ( format :: FULL_ISO , None ) )
282274 } else {
283275 let field = if let Some ( field) = field. strip_prefix ( "posix-" ) {
284276 // See GNU documentation, set format to "locale" if LC_TIME="POSIX",
@@ -288,16 +280,23 @@ fn parse_time_style(options: &clap::ArgMatches) -> Result<(String, Option<String
288280 if std:: env:: var ( "LC_TIME" ) . unwrap_or_default ( ) == "POSIX"
289281 || std:: env:: var ( "LC_ALL" ) . unwrap_or_default ( ) == "POSIX"
290282 {
291- return ok ( time_styles [ "locale" ] ) ;
283+ return ok ( LOCALE_FORMAT ) ;
292284 }
293285 field
294286 } else {
295287 & field
296288 } ;
297289
298- match time_styles. get ( field) {
299- Some ( formats) => ok ( * formats) ,
300- None => match field. chars ( ) . next ( ) . unwrap ( ) {
290+ match field {
291+ "full-iso" => ok ( ( format:: FULL_ISO , None ) ) ,
292+ "long-iso" => ok ( ( format:: LONG_ISO , None ) ) ,
293+ // ISO older format needs extra padding.
294+ "iso" => Ok ( (
295+ "%m-%d %H:%M" . to_string ( ) ,
296+ Some ( format:: ISO . to_string ( ) + " " ) ,
297+ ) ) ,
298+ "locale" => ok ( LOCALE_FORMAT ) ,
299+ _ => match field. chars ( ) . next ( ) . unwrap ( ) {
301300 '+' => {
302301 // recent/older formats are (optionally) separated by a newline
303302 let mut it = field[ 1 ..] . split ( '\n' ) ;
@@ -313,9 +312,9 @@ fn parse_time_style(options: &clap::ArgMatches) -> Result<(String, Option<String
313312 }
314313 }
315314 } else if options. get_flag ( options:: FULL_TIME ) {
316- ok ( time_styles [ "full-iso" ] )
315+ ok ( ( format :: FULL_ISO , None ) )
317316 } else {
318- ok ( time_styles [ "locale" ] )
317+ ok ( LOCALE_FORMAT )
319318 }
320319}
321320
0 commit comments