Tcl Source Code

Check-in [ef26db9e93]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make sure that adding 0 weekdays doesn't result in going back in time
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | gahr-bug-5f71353740 | tip-444
Files: files | file ages | folders
SHA1: ef26db9e936b1507387304f7363d209514c1cb3a
User & Date: gahr 2016-02-23 16:31:18
Context
2016-02-23
19:44
merge trunk check-in: 4c431fc1c9 user: gahr tags: gahr-bug-5f71353740, tip-444
16:31
Make sure that adding 0 weekdays doesn't result in going back in time check-in: ef26db9e93 user: gahr tags: gahr-bug-5f71353740, tip-444
2016-02-17
11:03
[5f71353740] Support the "weekdays" unit in [clock add] check-in: 2c9afbf911 user: gahr tags: tip-444
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to library/clock.tcl.

4444
4445
4446
4447
4448
4449
4450




4451
4452
4453
4454
4455
4456
4457
#
# Side effects:
#	None.
#
#----------------------------------------------------------------------

proc ::tcl::clock::AddWeekDays { days clockval timezone changeover } {





    set day [format $clockval -format %u]

    set weeks  [expr {$days / 5}]
    set rdays  [expr {$days % 5}]
    set toAdd  [expr {7 * $weeks + $rdays}]
    set resDay [expr {$day + ($toAdd % 7)}]






>
>
>
>







4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
#
# Side effects:
#	None.
#
#----------------------------------------------------------------------

proc ::tcl::clock::AddWeekDays { days clockval timezone changeover } {

    if {$days == 0} {
        return $clockval
    }

    set day [format $clockval -format %u]

    set weeks  [expr {$days / 5}]
    set rdays  [expr {$days % 5}]
    set toAdd  [expr {7 * $weeks + $rdays}]
    set resDay [expr {$day + ($toAdd % 7)}]

Changes to tests/clock.test.

35233
35234
35235
35236
35237
35238
35239





35240
35241
35242
35243
35244
35245
35246
35247
    set x1 [clock format $f1 -format {%Y-%m-%d}]
} {2013-11-25}
test clock-30.28 {clock add weekdays starting on Sunday} {
    set t [clock scan {2013-11-24}] ;# 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 {
    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






>
>
>
>
>
|







35233
35234
35235
35236
35237
35238
35239
35240
35241
35242
35243
35244
35245
35246
35247
35248
35249
35250
35251
35252
    set x1 [clock format $f1 -format {%Y-%m-%d}]
} {2013-11-25}
test clock-30.28 {clock add weekdays starting on Sunday} {
    set t [clock scan {2013-11-24}] ;# 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 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} {
        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