diff --git a/generic/tclClock.c b/generic/tclClock.c index 113a5d2..fdaa2d4 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -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)) { diff --git a/generic/tclClockFmt.c b/generic/tclClockFmt.c index 4c37ee3..1af0c68 100644 --- a/generic/tclClockFmt.c +++ b/generic/tclClockFmt.c @@ -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; } diff --git a/generic/tclDate.c b/generic/tclDate.c index 4b09954..f9d8dbc 100644 --- a/generic/tclDate.c +++ b/generic/tclDate.c @@ -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 */ diff --git a/generic/tclGetDate.y b/generic/tclGetDate.y index 89ccd24..d001155 100644 --- a/generic/tclGetDate.y +++ b/generic/tclGetDate.y @@ -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 */ diff --git a/tests/clock.test b/tests/clock.test index bf48516..84e933f 100644 --- a/tests/clock.test +++ b/tests/clock.test @@ -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