summaryrefslogtreecommitdiffstats
path: root/tests/clock.test
diff options
context:
space:
mode:
authorgahr <gahr@gahr.ch>2016-02-24 09:10:01 (GMT)
committergahr <gahr@gahr.ch>2016-02-24 09:10:01 (GMT)
commit369046f0c01b3e138f4f9b8c4bd74f1ca9c89111 (patch)
treec9f50577a62ea2f8671958367e4b6769099ad141 /tests/clock.test
parenta8436d381c941cc365c38eb2196ad1d5401a4b4a (diff)
downloadtcl-369046f0c01b3e138f4f9b8c4bd74f1ca9c89111.zip
tcl-369046f0c01b3e138f4f9b8c4bd74f1ca9c89111.tar.gz
tcl-369046f0c01b3e138f4f9b8c4bd74f1ca9c89111.tar.bz2
More comprehensive tests adding and subtracting week-days
Diffstat (limited to 'tests/clock.test')
-rw-r--r--tests/clock.test33
1 files changed, 23 insertions, 10 deletions
diff --git a/tests/clock.test b/tests/clock.test
index 0b26213..42285a8 100644
--- a/tests/clock.test
+++ b/tests/clock.test
@@ -35242,17 +35242,30 @@ test clock-30.29 {clock add 0 weekdays starting on a weekend} {
set f1 [clock add $t 0 weekdays]
set x1 [clock format $f1 -format {%Y-%m-%d}]
} {2016-02-27}
-test clock-30.30 {clock add weekdays systematic} -body {
+test clock-30.30 {clock add weekdays and back} -body {
set n [clock seconds]
- set d [clock format $n -format %u]
- for {set i 1} {$i < 100} {incr i} {
- set res_no [clock format [clock add $n $i weekdays] -format %u]
- set exp_mod [expr {($d+$i)%5}]
- if {$exp_mod == 0} {
- set exp_mod 5
- }
- if {$res_no != $exp_mod} {
- return "Got $res_no adding $i to $n, expected: $exp_mod"
+ # we start on each day of the week
+ for {set i 0} {$i < 7} {incr i} {
+ set start [clock add $n $i days]
+ set startu [clock format $start -format %u]
+ # add 0 - 100 weekdays
+ for {set j 0} {$j < 100} {incr j} {
+ set forth [clock add $start $j weekdays]
+ set back [clock add $forth -$j weekdays]
+ # If $s was a weekday or $j was 0, $b must be the same day.
+ # Otherwise, $b must be the immediately preceeding Friday
+ set fail 0
+ if {$j == 0 || $startu < 6} {
+ if {$start != $back} { set fail 1}
+ } else {
+ set friday [clock add $start -[expr {$startu % 5}] days]
+ if {$friday != $back} { set fail 1 }
+ }
+ if {$fail} {
+ set sdate [clock format $start -format {%Y-%m-%d}]
+ set bdate [clock format $back -format {%Y-%m-%d}]
+ return "$sdate + $j - $j := $bdate"
+ }
}
}
return "OK"