@@ -812,16 +812,13 @@ static int has_epoch_timestamp(const char *nameline)
812812 * 1970-01-01, and the seconds part must be "00".
813813 */
814814 const char stamp_regexp [] =
815- "^(1969-12-31|1970-01-01)"
816- " "
817- "[0-2][0-9]:[0-5][0-9]:00(\\.0+)?"
815+ "^[0-2][0-9]:([0-5][0-9]):00(\\.0+)?"
818816 " "
819817 "([-+][0-2][0-9]:?[0-5][0-9])\n" ;
820818 const char * timestamp = NULL , * cp , * colon ;
821819 static regex_t * stamp ;
822820 regmatch_t m [10 ];
823- int zoneoffset ;
824- int hourminute ;
821+ int zoneoffset , epoch_hour , hour , minute ;
825822 int status ;
826823
827824 for (cp = nameline ; * cp != '\n' ; cp ++ ) {
@@ -830,6 +827,18 @@ static int has_epoch_timestamp(const char *nameline)
830827 }
831828 if (!timestamp )
832829 return 0 ;
830+
831+ /*
832+ * YYYY-MM-DD hh:mm:ss must be from either 1969-12-31
833+ * (west of GMT) or 1970-01-01 (east of GMT)
834+ */
835+ if (skip_prefix (timestamp , "1969-12-31 " , & timestamp ))
836+ epoch_hour = 24 ;
837+ else if (skip_prefix (timestamp , "1970-01-01 " , & timestamp ))
838+ epoch_hour = 0 ;
839+ else
840+ return 0 ;
841+
833842 if (!stamp ) {
834843 stamp = xmalloc (sizeof (* stamp ));
835844 if (regcomp (stamp , stamp_regexp , REG_EXTENDED )) {
@@ -847,6 +856,9 @@ static int has_epoch_timestamp(const char *nameline)
847856 return 0 ;
848857 }
849858
859+ hour = strtol (timestamp , NULL , 10 );
860+ minute = strtol (timestamp + m [1 ].rm_so , NULL , 10 );
861+
850862 zoneoffset = strtol (timestamp + m [3 ].rm_so + 1 , (char * * ) & colon , 10 );
851863 if (* colon == ':' )
852864 zoneoffset = zoneoffset * 60 + strtol (colon + 1 , NULL , 10 );
@@ -855,20 +867,7 @@ static int has_epoch_timestamp(const char *nameline)
855867 if (timestamp [m [3 ].rm_so ] == '-' )
856868 zoneoffset = - zoneoffset ;
857869
858- /*
859- * YYYY-MM-DD hh:mm:ss must be from either 1969-12-31
860- * (west of GMT) or 1970-01-01 (east of GMT)
861- */
862- if ((zoneoffset < 0 && memcmp (timestamp , "1969-12-31" , 10 )) ||
863- (0 <= zoneoffset && memcmp (timestamp , "1970-01-01" , 10 )))
864- return 0 ;
865-
866- hourminute = (strtol (timestamp + 11 , NULL , 10 ) * 60 +
867- strtol (timestamp + 14 , NULL , 10 ) -
868- zoneoffset );
869-
870- return ((zoneoffset < 0 && hourminute == 1440 ) ||
871- (0 <= zoneoffset && !hourminute ));
870+ return hour * 60 + minute - zoneoffset == epoch_hour * 60 ;
872871}
873872
874873/*
0 commit comments