Subject: Make sure that adding 0 weekdays doesn't result in going back in time

From: gahr <[email-masked]>
Date: Tue, 23 Feb 2016 16:31:18 +0000

---
 library/clock.tcl | 4 ++++
 tests/clock.test  | 7 ++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/library/clock.tcl b/library/clock.tcl
index 231f1ae..535a67d 100755
--- a/library/clock.tcl
+++ b/library/clock.tcl
@@ -4449,6 +4449,10 @@ proc ::tcl::clock::AddMonths { months clockval timezone changeover } {
 
 proc ::tcl::clock::AddWeekDays { days clockval timezone changeover } {
 
+    if {$days == 0} {
+        return $clockval
+    }
+
     set day [format $clockval -format %u]
 
     set weeks  [expr {$days / 5}]
diff --git a/tests/clock.test b/tests/clock.test
index fc7992d..0b26213 100644
--- a/tests/clock.test
+++ b/tests/clock.test
@@ -35237,7 +35237,12 @@ test clock-30.28 {clock add weekdays starting on Sunday} {
     set f1 [clock add $t 1 weekday]
     set x1 [clock format $f1 -format {%Y-%m-%d}]
 } {2013-11-25}
-test clock-30.29 {clock add weekdays systematic} -body {
+test clock-30.29 {clock add 0 weekdays starting on a weekend} {
+    set t [clock scan {2016-02-27}] ;# Saturday
+    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 {
     set n [clock seconds]
     set d [clock format $n -format %u]
     for {set i 1} {$i < 100} {incr i} {
-- 
cgit v0.12