Tcl Source Code

Check-in [f991a78d7a]
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:More comprehensive tests adding and subtracting week-days
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | gahr-bug-5f71353740 | tip-444
Files: files | file ages | folders
SHA1: f991a78d7a6180becf1c44fdc8f0e6f56135fd58
User & Date: gahr 2016-02-24 09:10:01
Context
2016-03-03
08:30
Clarify that weekends are intended as Saturdays and Sundays check-in: aaa1b378a1 user: gahr tags: gahr-bug-5f71353740, tip-444
2016-02-24
09:10
More comprehensive tests adding and subtracting week-days check-in: f991a78d7a user: gahr tags: gahr-bug-5f71353740, tip-444
2016-02-23
19:44
merge trunk check-in: 4c431fc1c9 user: gahr tags: gahr-bug-5f71353740, tip-444
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to tests/clock.test.

35238
35239
35240
35241
35242
35243
35244
35245
35246
35247
35248
35249
35250
35251





35252





35253
35254
35255





35256
35257
35258
35259
35260
35261
35262
    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





        }
        if {$res_no != $exp_mod} {
            return "Got $res_no adding $i to $n, expected: $exp_mod"





        }
    }
    return "OK"
} -result {OK}

# END testcases30







|

|
|
|
|
|
>
>
>
>
>
|
>
>
>
>
>
|
<
<
>
>
>
>
>







35238
35239
35240
35241
35242
35243
35244
35245
35246
35247
35248
35249
35250
35251
35252
35253
35254
35255
35256
35257
35258
35259
35260
35261
35262
35263


35264
35265
35266
35267
35268
35269
35270
35271
35272
35273
35274
35275
    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 and back} -body {
    set n [clock seconds]
    # 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"
} -result {OK}

# END testcases30