@@ -552,23 +552,35 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
552552static int match_tz (const char * date , int * offp )
553553{
554554 char * end ;
555- int offset = strtoul (date + 1 , & end , 10 );
556- int min , hour ;
557- int n = end - date - 1 ;
555+ int hour = strtoul (date + 1 , & end , 10 );
556+ int n = end - ( date + 1 ) ;
557+ int min = 0 ;
558558
559- min = offset % 100 ;
560- hour = offset / 100 ;
559+ if (n == 4 ) {
560+ /* hhmm */
561+ min = hour % 100 ;
562+ hour = hour / 100 ;
563+ } else if (n != 2 ) {
564+ min = 99 ; /* random crap */
565+ } else if (* end == ':' ) {
566+ /* hh:mm? */
567+ min = strtoul (end + 1 , & end , 10 );
568+ if (end - (date + 1 ) != 5 )
569+ min = 99 ; /* random crap */
570+ } /* otherwise we parsed "hh" */
561571
562572 /*
563- * Don't accept any random crap.. At least 3 digits, and
564- * a valid minute. We might want to check that the minutes
565- * are divisible by 30 or something too.
573+ * Don't accept any random crap. Even though some places have
574+ * offset larger than 12 hours (e.g. Pacific/Kiritimati is at
575+ * UTC+14), there is something wrong if hour part is much
576+ * larger than that. We might also want to check that the
577+ * minutes are divisible by 15 or something too. (Offset of
578+ * Kathmandu, Nepal is UTC+5:45)
566579 */
567- if (min < 60 && n > 2 ) {
568- offset = hour * 60 + min ;
580+ if (min < 60 && hour < 24 ) {
581+ int offset = hour * 60 + min ;
569582 if (* date == '-' )
570583 offset = - offset ;
571-
572584 * offp = offset ;
573585 }
574586 return end - date ;
0 commit comments