summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclClock.c8
-rw-r--r--generic/tclClockFmt.c2
-rw-r--r--generic/tclDate.c18
-rw-r--r--generic/tclGetDate.y12
-rw-r--r--tests/clock.test24
5 files changed, 37 insertions, 27 deletions
diff --git a/generic/tclClock.c b/generic/tclClock.c
index 35353ff..20da59f 100644
--- a/generic/tclClock.c
+++ b/generic/tclClock.c
@@ -3739,13 +3739,19 @@ ClockScanCommit(
}
}
+ /* If seconds overflows the day (no validate case), increase days */
+ if (yySecondOfDay >= SECONDS_PER_DAY) {
+ yydate.julianDay += (yySecondOfDay / SECONDS_PER_DAY);
+ yySecondOfDay %= SECONDS_PER_DAY;
+ }
+
/* Local seconds to UTC (stored in yydate.seconds) */
if (info->flags & CLF_ASSEMBLE_SECONDS) {
yydate.localSeconds =
-210866803200LL
+ (SECONDS_PER_DAY * yydate.julianDay)
- + (yySecondOfDay % SECONDS_PER_DAY);
+ + yySecondOfDay;
}
if (info->flags & (CLF_ASSEMBLE_SECONDS | CLF_LOCALSEC)) {
diff --git a/generic/tclClockFmt.c b/generic/tclClockFmt.c
index c9b30bf..abd55ab 100644
--- a/generic/tclClockFmt.c
+++ b/generic/tclClockFmt.c
@@ -1792,7 +1792,7 @@ ClockScnToken_JDN_Proc(
fractJD = (int)tok->map->offs /* 0 for calendar or 43200 for astro JD */
+ (int)((Tcl_WideInt)SECONDS_PER_DAY * fractJD / fractJDDiv);
- if (fractJD > SECONDS_PER_DAY) {
+ if (fractJD >= SECONDS_PER_DAY) {
fractJD %= SECONDS_PER_DAY;
intJD += 1;
}
diff --git a/generic/tclDate.c b/generic/tclDate.c
index 7ce26ef..fe6f088 100644
--- a/generic/tclDate.c
+++ b/generic/tclDate.c
@@ -69,6 +69,7 @@
#define yylex TclDatelex
#define yyerror TclDateerror
#define yydebug TclDatedebug
+#define yynerrs TclDatenerrs
/* First part of user prologue. */
@@ -1212,6 +1213,9 @@ static YYLTYPE yyloc_default
;
YYLTYPE yylloc = yyloc_default;
+ /* Number of syntax errors so far. */
+ int yynerrs = 0;
+
yy_state_fast_t yystate = 0;
/* Number of tokens to shift before error messages enabled. */
int yyerrstatus = 0;
@@ -1952,6 +1956,7 @@ yyerrlab:
/* If not already recovering from an error, report this error. */
if (!yyerrstatus)
{
+ ++yynerrs;
yyerror (&yylloc, info, YY_("syntax error"));
}
@@ -1988,6 +1993,7 @@ yyerrorlab:
label yyerrorlab therefore never appears in user code. */
if (0)
YYERROR;
+ ++yynerrs;
/* Do not reclaim the symbols of the rule whose action triggered
this YYERROR. */
@@ -2338,24 +2344,12 @@ ToSeconds(
int Seconds,
MERIDIAN Meridian)
{
- if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) {
- return -1;
- }
switch (Meridian) {
case MER24:
- if (Hours < 0 || Hours > 23) {
- return -1;
- }
return (Hours * 60 + Minutes) * 60 + Seconds;
case MERam:
- if (Hours < 1 || Hours > 12) {
- return -1;
- }
return ((Hours % 12) * 60 + Minutes) * 60 + Seconds;
case MERpm:
- if (Hours < 1 || Hours > 12) {
- return -1;
- }
return (((Hours % 12) + 12) * 60 + Minutes) * 60 + Seconds;
}
return -1; /* Should never be reached */
diff --git a/generic/tclGetDate.y b/generic/tclGetDate.y
index 211fe83..83331e2 100644
--- a/generic/tclGetDate.y
+++ b/generic/tclGetDate.y
@@ -714,24 +714,12 @@ ToSeconds(
int Seconds,
MERIDIAN Meridian)
{
- if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) {
- return -1;
- }
switch (Meridian) {
case MER24:
- if (Hours < 0 || Hours > 23) {
- return -1;
- }
return (Hours * 60 + Minutes) * 60 + Seconds;
case MERam:
- if (Hours < 1 || Hours > 12) {
- return -1;
- }
return ((Hours % 12) * 60 + Minutes) * 60 + Seconds;
case MERpm:
- if (Hours < 1 || Hours > 12) {
- return -1;
- }
return (((Hours % 12) + 12) * 60 + Minutes) * 60 + Seconds;
}
return -1; /* Should never be reached */
diff --git a/tests/clock.test b/tests/clock.test
index 0144512..7857b22 100644
--- a/tests/clock.test
+++ b/tests/clock.test
@@ -37154,7 +37154,29 @@ test clock-46.6 {freescan: regression test - bad time} -constraints valid_off \
# 13:00 am/pm are invalid input strings...
list [clock scan "13:00 am" -base 0 -gmt 1] \
[clock scan "13:00 pm" -base 0 -gmt 1]
- } -result {-1 -1}
+ } -result {3600 46800}
+
+if {!$valid_mode} {
+ test clock-46.7a {regression test - switch day by large not-valid time, see bug [3ee8f1c2a785f4d8]} {valid_off} {
+ list [clock scan 23:59:59 -base 0 -gmt 1 -format %H:%M:%S] \
+ [clock scan 24:00:00 -base 0 -gmt 1 -format %H:%M:%S] \
+ [clock scan 48:00:00 -base 0 -gmt 1 -format %H:%M:%S]
+ } {86399 86400 172800}
+ test clock-46.7b {freescan: regression test - switch day by large not-valid time, see bug [3ee8f1c2a785f4d8]} {valid_off} {
+ list [clock scan 23:59:59 -base 0 -gmt 1] \
+ [clock scan 24:00:00 -base 0 -gmt 1] \
+ [clock scan 48:00:00 -base 0 -gmt 1]
+ } {86399 86400 172800}
+} else {
+ test clock-46.8a {regression test - invalid time (hour)} {
+ list [catch {clock scan 24:00:00 -base 0 -gmt 1 -format %H:%M:%S} msg] $msg \
+ [catch {clock scan 48:00:00 -base 0 -gmt 1 -format %H:%M:%S} msg] $msg
+ } {1 {unable to convert input string: invalid time (hour)} 1 {unable to convert input string: invalid time (hour)}}
+ test clock-46.8b {freescan: regression test - invalid time (hour)} {
+ list [catch {clock scan 24:00:00 -base 0 -gmt 1} msg] $msg \
+ [catch {clock scan 48:00:00 -base 0 -gmt 1} msg] $msg
+ } {1 {unable to convert input string: invalid time (hour)} 1 {unable to convert input string: invalid time (hour)}}
+}
proc _invalid_test {args} {
global valid_mode