Skip to content

Commit

Permalink
fixed validation of day of week for 24:00 (move to next day)
Browse files Browse the repository at this point in the history
closes [882da1e28b]
  • Loading branch information
sebres committed Nov 25, 2024
1 parent 6825daf commit 954b16f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 26 deletions.
8 changes: 7 additions & 1 deletion generic/tclClock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2537,7 +2537,7 @@ GetYearWeekDay(
dayOfFiscalYear = fields->julianDay - temp.julianDay;
fields->iso8601Week = (dayOfFiscalYear / 7) + 1;
fields->dayOfWeek = (dayOfFiscalYear + 1) % 7;
if (fields->dayOfWeek < 1) {
if (fields->dayOfWeek < 1) { /* Mon .. Sun == 1 .. 7 */
fields->dayOfWeek += 7;
}
}
Expand Down Expand Up @@ -3888,6 +3888,12 @@ ClockValidDate(
errCode = "time";
goto error;
}
/* 24:00 is next day 00:00, correct day of week if given */
if (info->flags & CLF_DAYOFWEEK) {
if (++yyDayOfWeek > 7) { /* Mon .. Sun == 1 .. 7 */
yyDayOfWeek = 1;
}
}
} else {
errMsg = "invalid time (hour)";
errCode = "hour";
Expand Down
72 changes: 47 additions & 25 deletions tests/clock.test
Original file line number Diff line number Diff line change
Expand Up @@ -38438,6 +38438,31 @@ test clock-67.5 {Change scan %x output on global locale change [Bug 4a0c163d24]}
msgcat::mclocale $current
} -result {1}

proc _check_scan {res_ d tz fmt i {fmt2str ""}} {
upvar $res_ res
# expectation is fail on result like "invalid time":
set e [expr {![string is wideinteger -strict $i] && [string match "*invalid*" $i]}];
# conversion:
set lmscan {{args} {
upvar d d tz tz fmt fmt fmt2str fmt2str
set s [clock scan $d -timezone $tz {*}$args]
if {$fmt2str eq ""} {
set s
} else {
clock format $s -timezone $tz -locale en -format $fmt2str
}
}}
# check with free scan:
set v [catch { apply $lmscan } t]
if {($v != $e) || (!$e ? $t != $i : ![string match "*$i*" $t])} {
lappend res "free-scan \"$d\" [expr {!$v ? "succeeds" : "fails"}] with \"$t\" expected [expr {!$e ? "success" : "fail"}] with \"$i\""
}
# check with formatted scan:
set v [catch { apply $lmscan -locale en -format $fmt } t]
if {($v != $e) || (!$e ? $t != $i : ![string match "*$i*" $t])} {
lappend res "frmt-scan \"$d\" [expr {!$v ? "succeeds" : "fails"}] with \"$t\" expected [expr {!$e ? "success" : "fail"}] with \"$i\""
}
}
test clock-68.1 {Leap second, minute, hour [f2b5f89c0d], regression test (no validity check)} -constraints valid_off -body {
set res {}
foreach {d i} {
Expand All @@ -38447,30 +38472,33 @@ test clock-68.1 {Leap second, minute, hour [f2b5f89c0d], regression test (no val
"2012-05-30 24:00:60" 1338422460
"2012-05-30 24:60:00" 1338426000
} {
# check with free scan:
if {[set t [clock scan $d -gmt 1]] != $i} {
lappend res "free-scan \"$d\" == $t, expected $i"
}
# check with formatted scan:
if {[set t [clock scan $d -gmt 1 -format "%Y-%m-%d %H:%M:%S"]] != $i} {
lappend res "frmt-scan \"$d\" == $t, expected $i"
}
# check with free and format scan:
_check_scan res $d UTC "%Y-%m-%d %H:%M:%S" $i
}
join $res \n; # must be empty
} -result {}
test clock-68.1a {24:00 time [aee9f2b916], regression test} -body {
set res {}
foreach {d i} {
"2012-06-30 24:00:00" 1341100800
} {
# check with free scan:
if {[set t [clock scan $d -gmt 1]] != $i} {
lappend res "free-scan \"$d\" == $t, expected $i"
}
# check with formatted scan:
if {[set t [clock scan $d -gmt 1 -format "%Y-%m-%d %H:%M:%S"]] != $i} {
lappend res "frmt-scan \"$d\" == $t, expected $i"
}
} {
# check with free and format scan:
_check_scan res $d UTC "%Y-%m-%d %H:%M:%S" $i
}
join $res \n; # must be empty
} -result {}
test clock-68.1b {24:00 time [aee9f2b916], [882da1e28b], regression test} -body {
set res {}
foreach {d tz i} {
"Sat, 2012-06-30 24:00:00 GMT" GMT 1341100800
"Sat, 2012-06-30 24:00:00 +1145" +1145 1341058500
"Sat, 2012-06-30 24:00:00 -1145" -1145 1341143100
"Sun, 2012-07-01 24:00:00 GMT" GMT 1341187200
"Sun, 2012-07-01 24:00:00 +1145" +1145 1341144900
"Sun, 2012-07-01 24:00:00 -1145" -1145 1341229500
} {
# check with free and format scan:
_check_scan res $d $tz "%a, %Y-%m-%d %H:%M:%S %z" $i
}
join $res \n; # must be empty
} -result {}
Expand All @@ -38487,14 +38515,8 @@ test clock-68.2 {Leap second, "24:00", regression test (validity check)} -constr
"2012-06-30 23:59:60" "invalid time"
"2018-06-30 23:59:60" "invalid time"
} {
# check with free scan:
if {![catch { clock scan $d -gmt 1 } t] || ![string match *$i* $t]} {
lappend res "free-scan \"$d\" == \"$t\", expected \"$i\""
}
# check with formatted scan:
if {![catch { clock scan $d -gmt 1 -format "%Y-%m-%d %H:%M:%S" } t] || ![string match *$i* $t]} {
lappend res "frmt-scan \"$d\" == \"$t\", expected \"$i\""
}
# check with free and format scan:
_check_scan res $d UTC "%Y-%m-%d %H:%M:%S" $i
}
join $res \n; # must be empty
} -result {}
Expand Down

0 comments on commit 954b16f

Please sign in to comment.