From 922dedc270c32b3453e0827c5f60e687a84754e4 Mon Sep 17 00:00:00 2001 From: sebres Date: Tue, 16 Jul 2024 21:59:53 +0200 Subject: [PATCH] fix validation check for scanned Sunday (missing % 7 by compare of estimated value with input value) --- generic/tclClock.c | 2 +- tests/clock.test | 31 +++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/generic/tclClock.c b/generic/tclClock.c index fdaa2d4..c999655 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -3956,7 +3956,7 @@ ClockValidDate( tempCpyFlg = 1; } GetYearWeekDay(&temp, GREGORIAN_CHANGE_DATE); - if (temp.dayOfWeek != yyDayOfWeek) { + if ((temp.dayOfWeek % 7) != (yyDayOfWeek % 7)) { errMsg = "invalid day of week"; errCode = "day of week"; goto error; } } diff --git a/tests/clock.test b/tests/clock.test index 84e933f..fba03a9 100644 --- a/tests/clock.test +++ b/tests/clock.test @@ -37159,12 +37159,15 @@ if {!$valid_mode} { } {1 {unable to convert input string: invalid time (hour)} 1 {unable to convert input string: invalid time (hour)}} } -proc _invalid_test {args} { +proc _invalid_test {testtz args} { global valid_mode # ensure validation works TZ independently, since the conversion # of local time to UTC may adjust date/time tokens, depending on TZ: set res {} - foreach tz {:GMT :CET {} :Europe/Berlin :localtime} { + if {$testtz eq ""} { + set testtz {:GMT :CET {} :Europe/Berlin :localtime} + } + foreach tz $testtz { foreach {v} $args { if {$valid_mode} { # globally -valid 1 lappend res [catch {clock scan $v -timezone $tz} msg] $msg @@ -37180,46 +37183,54 @@ foreach {idx relstr} {"" "" "+rel" "+ 15 month + 40 days + 30 hours + 80 minutes test clock-46.10$idx {freescan: validation rules: invalid time} \ -body { # 13:00 am/pm are invalid input strings... - _invalid_test "13:00 am$relstr" "13:00 pm$relstr" + _invalid_test {} "13:00 am$relstr" "13:00 pm$relstr" } -result [lrepeat 10 1 {unable to convert input string: invalid time (hour)}] test clock-46.11$idx {freescan: validation rules: invalid time} \ -body { # invalid minutes in input strings... - _invalid_test "23:70$relstr" "11:80 pm$relstr" + _invalid_test {} "23:70$relstr" "11:80 pm$relstr" } -result [lrepeat 10 1 {unable to convert input string: invalid time (minutes)}] test clock-46.12$idx {freescan: validation rules: invalid time} \ -body { # invalid seconds in input strings... - _invalid_test "23:00:70$relstr" "11:00:80 pm$relstr" + _invalid_test {} "23:00:70$relstr" "11:00:80 pm$relstr" } -result [lrepeat 10 1 {unable to convert input string: invalid time}] test clock-46.13$idx {freescan: validation rules: invalid day} \ -body { - _invalid_test "29 Feb 2017$relstr" "30 Feb 2016$relstr" + _invalid_test {} "29 Feb 2017$relstr" "30 Feb 2016$relstr" } -result [lrepeat 10 1 {unable to convert input string: invalid day}] test clock-46.14$idx {freescan: validation rules: invalid day} \ -body { - _invalid_test "0 Feb 2017$relstr" "00 Feb 2017$relstr" + _invalid_test {} "0 Feb 2017$relstr" "00 Feb 2017$relstr" } -result [lrepeat 10 1 {unable to convert input string: invalid day}] test clock-46.15$idx {freescan: validation rules: invalid month} \ -body { - _invalid_test "13/13/2017$relstr" "00/00/2017$relstr" + _invalid_test {} "13/13/2017$relstr" "00/00/2017$relstr" } -result [lrepeat 10 1 {unable to convert input string: invalid month}] test clock-46.16$idx {freescan: validation rules: invalid day of week} \ -body { - _invalid_test "Sat Jan 02 00:00:00 1970$relstr" "Thu Jan 04 00:00:00 1970$relstr" + _invalid_test {} "Sat Jan 02 00:00:00 1970$relstr" "Thu Jan 04 00:00:00 1970$relstr" } -result [lrepeat 10 1 {unable to convert input string: invalid day of week}] test clock-46.17$idx {scan: validation rules: invalid year} -setup { set orgcfg [list -min-year [clock configure -min-year] -max-year [clock configure -max-year] \ -year-century [clock configure -year-century] -century-switch [clock configure -century-switch]] clock configure -min-year 2000 -max-year 2100 -year-century 2000 -century-switch 38 } -body { - _invalid_test "70-01-01$relstr" "1870-01-01$relstr" "9570-01-01$relstr" + _invalid_test {} "70-01-01$relstr" "1870-01-01$relstr" "9570-01-01$relstr" } -result [lrepeat 15 1 {unable to convert input string: invalid year}] -cleanup { clock configure {*}$orgcfg unset -nocomplain orgcfg } }; # foreach +test clock-46.16-pos {freescan: validation rules: valid day of week (must work for all weekdays)} \ + -body { + _invalid_test {:GMT -12:00 +12:00} {Sat, 01 Jan 2000 00:00:00} {Sun, 02 Jan 2000 00:00:00} {Mon, 03 Jan 2000 00:00:00} {Tue, 04 Jan 2000 00:00:00} {Wed, 05 Jan 2000 00:00:00} {Thu, 06 Jan 2000 00:00:00} {Fri, 07 Jan 2000 00:00:00} + } -result [list \ + 0 946684800 0 946771200 0 946857600 0 946944000 0 947030400 0 947116800 0 947203200 \ + 0 946728000 0 946814400 0 946900800 0 946987200 0 947073600 0 947160000 0 947246400 \ + 0 946641600 0 946728000 0 946814400 0 946900800 0 946987200 0 947073600 0 947160000 \ + ] rename _invalid_test {} unset -nocomplain idx relstr