Skip to content

Commit

Permalink
Fix [aee9f2b916]: clock scan -validate, ISO-8601, 24:00.
Browse files Browse the repository at this point in the history
Remove HAVE_MKTIME: It isn't used anywhere any more
  • Loading branch information
jan.nijtmans committed Nov 20, 2024
2 parents 67cd3a9 + be06da0 commit 85a7c5f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 33 deletions.
18 changes: 5 additions & 13 deletions generic/tclClock.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@
#include "tclStrIdxTree.h"
#include "tclDate.h"

/*
* Windows has mktime. The configurators do not check.
*/

#ifdef _WIN32
#define HAVE_MKTIME 1
#endif

/*
* Table of the days in each month, leap and common years
*/
Expand Down Expand Up @@ -3741,8 +3733,8 @@ ClockScanCommit(
}
}

/* If seconds overflows the day (no validate case), increase days */
if (yySecondOfDay >= SECONDS_PER_DAY) {
/* If seconds overflows the day (no validate and "24:00" case), increase days */
if (yySecondOfDay >= SECONDS_PER_DAY + ((info->flags & CLF_TIME) && (yyHour == 24))) {
yydate.julianDay += (yySecondOfDay / SECONDS_PER_DAY);
yySecondOfDay %= SECONDS_PER_DAY;
}
Expand Down Expand Up @@ -3886,19 +3878,19 @@ ClockValidDate(

if (info->flags & CLF_TIME) {
/* hour */
if (yyHour < 0 || yyHour > ((yyMeridian == MER24) ? 23 : 12)) {
if (yyHour < 0 || yyHour > ((yyMeridian == MER24) ? 24 : 12)) {
errMsg = "invalid time (hour)";
errCode = "hour";
goto error;
}
/* minutes */
if (yyMinutes < 0 || yyMinutes > 59) {
if (yyMinutes < 0 || yyMinutes > 59 || (yyMinutes && (yyHour == 24))) {
errMsg = "invalid time (minutes)";
errCode = "minutes";
goto error;
}
/* oldscan could return secondOfDay (parsedTime) -1 by invalid time (ex.: 25:00:00) */
if (yySeconds < 0 || yySeconds > 59 || yySecondOfDay <= -1) {
if (yySeconds < 0 || yySeconds > 59 || yySecondOfDay <= -1 || (yySeconds && (yyHour == 24))) {
errMsg = "invalid time";
errCode = "seconds";
goto error;
Expand Down
4 changes: 2 additions & 2 deletions generic/tclDate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2348,9 +2348,9 @@ ToSeconds(
case MER24:
return (Hours * 60 + Minutes) * 60 + Seconds;
case MERam:
return ((Hours % 12) * 60 + Minutes) * 60 + Seconds;
return (((Hours / 24) * 24 + (Hours % 12)) * 60 + Minutes) * 60 + Seconds;
case MERpm:
return (((Hours % 12) + 12) * 60 + Minutes) * 60 + Seconds;
return (((Hours / 24) * 24 + (Hours % 12) + 12) * 60 + Minutes) * 60 + Seconds;
}
return -1; /* Should never be reached */
}
Expand Down
4 changes: 2 additions & 2 deletions generic/tclGetDate.y
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,9 @@ ToSeconds(
case MER24:
return (Hours * 60 + Minutes) * 60 + Seconds;
case MERam:
return ((Hours % 12) * 60 + Minutes) * 60 + Seconds;
return (((Hours / 24) * 24 + (Hours % 12)) * 60 + Minutes) * 60 + Seconds;
case MERpm:
return (((Hours % 12) + 12) * 60 + Minutes) * 60 + Seconds;
return (((Hours / 24) * 24 + (Hours % 12) + 12) * 60 + Minutes) * 60 + Seconds;
}
return -1; /* Should never be reached */
}
Expand Down
12 changes: 6 additions & 6 deletions tests/clock.test
Original file line number Diff line number Diff line change
Expand Up @@ -37181,13 +37181,13 @@ if {!$valid_mode} {
} {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 \
list [catch {clock scan 24:00:01 -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)}}
} {1 {unable to convert input string: invalid time} 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 \
list [catch {clock scan 24:00:01 -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)}}
} {1 {unable to convert input string: invalid time} 1 {unable to convert input string: invalid time (hour)}}
}

proc _invalid_test {testtz scnargs args} {
Expand Down Expand Up @@ -38469,8 +38469,8 @@ test clock-68.2 {Leap second, minute, hour [f2b5f89c0d], regression test (validi
"2012-06-29 23:59:60" "invalid time"
"2012-05-30 23:59:60" "invalid time"
"2012-05-30 23:60:60" "invalid time"
"2012-05-30 24:00:60" "invalid time"
"2012-05-30 24:60:00" "invalid time"
"2012-05-30 24:00:01" "invalid time"
"2012-05-30 24:01:00" "invalid time"
} {
# check with free scan:
if {![catch { clock scan $d -gmt 1 } t] || ![string match *$i* $t]} {
Expand Down
6 changes: 0 additions & 6 deletions unix/configure
Original file line number Diff line number Diff line change
Expand Up @@ -9615,12 +9615,6 @@ if test "x$ac_cv_func_localtime_r" = xyes
then :
printf "%s\n" "#define HAVE_LOCALTIME_R 1" >>confdefs.h

fi
ac_fn_c_check_func "$LINENO" "mktime" "ac_cv_func_mktime"
if test "x$ac_cv_func_mktime" = xyes
then :
printf "%s\n" "#define HAVE_MKTIME 1" >>confdefs.h

fi


Expand Down
2 changes: 1 addition & 1 deletion unix/tcl.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,7 @@ AC_DEFUN([SC_TIME_HANDLER], [
AC_CHECK_HEADERS(sys/time.h)
AC_CHECK_HEADERS_ONCE([sys/time.h])
AC_CHECK_FUNCS(gmtime_r localtime_r mktime)
AC_CHECK_FUNCS(gmtime_r localtime_r)
AC_CACHE_CHECK([tm_tzadj in struct tm], tcl_cv_member_tm_tzadj, [
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <time.h>]], [[struct tm tm; (void)tm.tm_tzadj;]])],
Expand Down
3 changes: 0 additions & 3 deletions unix/tclConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@
/* Define to 1 if you have the 'mkstemps' function. */
#undef HAVE_MKSTEMPS

/* Define to 1 if you have the 'mktime' function. */
#undef HAVE_MKTIME

/* Do we have MT-safe gethostbyaddr() ? */
#undef HAVE_MTSAFE_GETHOSTBYADDR

Expand Down

0 comments on commit 85a7c5f

Please sign in to comment.