Skip to content

Commit

Permalink
fix validation check for scanned Sunday (missing % 7 by compare of es…
Browse files Browse the repository at this point in the history
…timated value with input value)
  • Loading branch information
sebres committed Jul 16, 2024
1 parent acbacc8 commit 922dedc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion generic/tclClock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
31 changes: 21 additions & 10 deletions tests/clock.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 922dedc

Please sign in to comment.