Tcl Source Code

Artifact [e2a9376afd]
Login

Artifact e2a9376afd233ee6417797b5a0c65f1f29d6ac12e9ec68231b2d0343dbfd875d:

Attachment "clock-freescan-hh-zone-lookahead-safe.patch" to ticket [7bad415e3e] added by kenneth.kienle 2026-09-03 19:55:47. (unpublished)
--- a/generic/tclGetDate.y
+++ b/generic/tclGetDate.y
@@ -99,6 +99,7 @@
     time_t *dateRelPointer;
 
     int dateDigitCount;
+    int datePrevDigitCount;
 } DateInfo;
 
 #define YYMALLOC	ckalloc
@@ -128,6 +129,7 @@
 #define yyRelPointer	(info->dateRelPointer)
 #define yyInput		(info->dateInput)
 #define yyDigitCount	(info->dateDigitCount)
+#define yyPrevDigitCount	(info->datePrevDigitCount)
 
 #define EPOCH		1970
 #define START_OF_TIME	1902
@@ -292,7 +294,15 @@
 	    yyDSTmode = DSTon;
 	}
 	| sign tUNUMBER {
-	    yyTimezone = -$1*($2 % 100 + ($2 / 100) * 60);
+	    /*
+	     * "+02" is hours, "+0200" is hhmm. The lexer counts the digits of the
+	     * LAST number it read: when the parser has taken a numeric lookahead
+	     * to decide this reduction, that count is the lookahead's and the
+	     * zone's is the one before it.
+	     */
+	    int digits = (yychar == tUNUMBER || yychar == tISOBASE)
+		    ? yyPrevDigitCount : yyDigitCount;
+	    yyTimezone = -$1*(digits <= 2 ? $2 * 60 : $2 % 100 + ($2 / 100) * 60);
 	    yyDSTmode = DSToff;
 	}
 	;
@@ -891,6 +901,7 @@
 		Count++;
 	    }
 	    yyInput--;
+	    yyPrevDigitCount = yyDigitCount;
 	    yyDigitCount = Count;
 
 	    /*
@@ -958,6 +969,8 @@
 
     yyInput = TclGetString(objv[1]);
     dateInfo.dateStart = yyInput;
+    yyDigitCount = 0;
+    yyPrevDigitCount = 0;
 
     yyHaveDate = 0;
     if (Tcl_GetIntFromObj(interp, objv[2], &yr) != TCL_OK
--- a/generic/tclDate.c
+++ b/generic/tclDate.c
@@ -151,6 +151,7 @@
     time_t *dateRelPointer;
 
     int dateDigitCount;
+    int datePrevDigitCount;
 } DateInfo;
 
 #define YYMALLOC	ckalloc
@@ -180,6 +181,7 @@
 #define yyRelPointer	(info->dateRelPointer)
 #define yyInput		(info->dateInput)
 #define yyDigitCount	(info->dateDigitCount)
+#define yyPrevDigitCount	(info->datePrevDigitCount)
 
 #define EPOCH		1970
 #define START_OF_TIME	1902
@@ -1608,7 +1610,15 @@
 
   case 19: /* zone: sign tUNUMBER  */
                         {
-	    yyTimezone = -(yyvsp[-1].Number)*((yyvsp[0].Number) % 100 + ((yyvsp[0].Number) / 100) * 60);
+	    /*
+	     * "+02" is hours, "+0200" is hhmm. The lexer counts the digits of the
+	     * LAST number it read: when the parser has taken a numeric lookahead
+	     * to decide this reduction, that count is the lookahead's and the
+	     * zone's is the one before it.
+	     */
+	    int digits = (yychar == tUNUMBER || yychar == tISOBASE)
+		    ? yyPrevDigitCount : yyDigitCount;
+	    yyTimezone = -(yyvsp[-1].Number)*(digits <= 2 ? (yyvsp[0].Number) * 60 : (yyvsp[0].Number) % 100 + ((yyvsp[0].Number) / 100) * 60);
 	    yyDSTmode = DSToff;
 	}
     break;
@@ -2489,6 +2499,7 @@
 		Count++;
 	    }
 	    yyInput--;
+	    yyPrevDigitCount = yyDigitCount;
 	    yyDigitCount = Count;
 
 	    /*
@@ -2556,6 +2567,8 @@
 
     yyInput = TclGetString(objv[1]);
     dateInfo.dateStart = yyInput;
+    yyDigitCount = 0;
+    yyPrevDigitCount = 0;
 
     yyHaveDate = 0;
     if (Tcl_GetIntFromObj(interp, objv[2], &yr) != TCL_OK