@@ -74,7 +74,7 @@ struct Settings {
7474 utc : bool ,
7575 format : Format ,
7676 date_source : DateSource ,
77- set_to : Option < DateTime < FixedOffset > > ,
77+ set_to : Option < String > ,
7878}
7979
8080/// Various ways of displaying the date
@@ -185,22 +185,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
185185 DateSource :: Now
186186 } ;
187187
188- let set_to = match matches. get_one :: < String > ( OPT_SET ) . map ( parse_date) {
189- None => None ,
190- Some ( Err ( ( input, _err) ) ) => {
191- return Err ( USimpleError :: new (
192- 1 ,
193- format ! ( "invalid date {}" , input. quote( ) ) ,
194- ) ) ;
195- }
196- Some ( Ok ( date) ) => Some ( date) ,
197- } ;
188+ let set_to = matches. get_one :: < String > ( OPT_SET ) ;
198189
199190 let settings = Settings {
200191 utc : matches. get_flag ( OPT_UNIVERSAL ) ,
201192 format,
202193 date_source,
203- set_to,
194+ set_to : set_to . cloned ( ) ,
204195 } ;
205196
206197 // Get the current time, either in the local time zone or UTC.
@@ -213,7 +204,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
213204 } ;
214205
215206 // Iterate over all dates - whether it's a single date or a file.
216- let dates: Box < dyn Iterator < Item = _ > > = if let Some ( date) = settings. set_to {
207+ let dates: Box < dyn Iterator < Item = _ > > = if let Some ( date_string) = & settings. set_to {
208+ let date = parse_datetime:: parse_datetime_at_date ( now. into ( ) , date_string)
209+ . map_err ( |_| USimpleError :: new ( 1 , format ! ( "invalid date {}" , date_string. quote( ) ) ) ) ?;
217210 // All set time functions expect UTC datetimes.
218211 let date: DateTime < Utc > = if settings. utc {
219212 date. with_timezone ( & Utc )
0 commit comments