@@ -203,7 +203,48 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
203203 // Iterate over all dates - whether it's a single date or a file.
204204 let dates: Box < dyn Iterator < Item = _ > > = match settings. date_source {
205205 DateSource :: Human ( ref input) => {
206- let date = parse_date ( input) ;
206+ // GNU compatibility (Pure numbers in date strings):
207+ // - Manual: https://www.gnu.org/software/coreutils/manual/html_node/Pure-numbers-in-date-strings.html
208+ // - Semantics: a pure decimal number denotes today’s time-of-day (HH or HHMM).
209+ // Examples: "0"/"00" => 00:00 today; "7"/"07" => 07:00 today; "0700" => 07:00 today.
210+ // For all other forms, fall back to the general parser.
211+ let is_pure_digits =
212+ !input. is_empty ( ) && input. len ( ) <= 4 && input. chars ( ) . all ( |c| c. is_ascii_digit ( ) ) ;
213+
214+ let date = if is_pure_digits {
215+ // Derive HH and MM from the input
216+ let ( hh_opt, mm_opt) = if input. len ( ) <= 2 {
217+ ( input. parse :: < u32 > ( ) . ok ( ) , Some ( 0u32 ) )
218+ } else {
219+ let ( h, m) = input. split_at ( input. len ( ) - 2 ) ;
220+ ( h. parse :: < u32 > ( ) . ok ( ) , m. parse :: < u32 > ( ) . ok ( ) )
221+ } ;
222+
223+ if let ( Some ( hh) , Some ( mm) ) = ( hh_opt, mm_opt) {
224+ // Compose a concrete datetime string for today with zone offset.
225+ // Use the already-determined 'now' and settings.utc to select offset.
226+ let date_part =
227+ strtime:: format ( "%F" , & now) . unwrap_or_else ( |_| String :: from ( "1970-01-01" ) ) ;
228+ // If -u, force +00:00; otherwise use the local offset of 'now'.
229+ let offset = if settings. utc {
230+ String :: from ( "+00:00" )
231+ } else {
232+ strtime:: format ( "%:z" , & now) . unwrap_or_default ( )
233+ } ;
234+ let composed = if offset. is_empty ( ) {
235+ format ! ( "{date_part} {hh:02}:{mm:02}" )
236+ } else {
237+ format ! ( "{date_part} {hh:02}:{mm:02} {offset}" )
238+ } ;
239+ parse_date ( composed)
240+ } else {
241+ // Fallback on parse failure of digits
242+ parse_date ( input)
243+ }
244+ } else {
245+ parse_date ( input)
246+ } ;
247+
207248 let iter = std:: iter:: once ( date) ;
208249 Box :: new ( iter)
209250 }
0 commit comments