Skip to content

Commit

Permalink
fixed regression [3ee8f1c2a785f4d8]: time overflow (without validatio…
Browse files Browse the repository at this point in the history
…n) must cause day increment;

clock.test: more regression tests
  • Loading branch information
sebres committed Jul 16, 2024
1 parent c2cecce commit acbacc8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
12 changes: 9 additions & 3 deletions generic/tclClock.c
Original file line number Diff line number Diff line change
Expand Up @@ -3777,13 +3777,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 =
-210866803200L
+ ( SECONDS_PER_DAY * (Tcl_WideInt)yydate.julianDay )
+ ( yySecondOfDay % SECONDS_PER_DAY );
-210866803200LL
+ (SECONDS_PER_DAY * yydate.julianDay)
+ yySecondOfDay;
}

if (info->flags & (CLF_ASSEMBLE_SECONDS|CLF_LOCALSEC)) {
Expand Down
2 changes: 1 addition & 1 deletion generic/tclClockFmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ ClockScnToken_JDN_Proc(ClockFmtScnCmdArgs *opts,

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;
}
Expand Down
12 changes: 0 additions & 12 deletions generic/tclDate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2360,24 +2360,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 */
Expand Down
12 changes: 0 additions & 12 deletions generic/tclGetDate.y
Original file line number Diff line number Diff line change
Expand Up @@ -730,24 +730,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 */
Expand Down
24 changes: 23 additions & 1 deletion tests/clock.test
Original file line number Diff line number Diff line change
Expand Up @@ -37135,7 +37135,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
Expand Down

0 comments on commit acbacc8

Please sign in to comment.