Tcl Source Code

Diff
Login

Differences From Artifact [629251fbb3]:

To Artifact [71bd2e9833]:


1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
# clock.test --
#
#	This test file covers the 'clock' command that manipulates time.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands. Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 2004 by Kevin B. Kenny.  All rights reserved.

#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest 2
    namespace import -force ::tcltest::*









>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# clock.test --
#
#	This test file covers the 'clock' command that manipulates time.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands. Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 2004 by Kevin B. Kenny.  All rights reserved.
# Copyright (c) 2015 by Sergey G. Brester aka sebres.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest 2
    namespace import -force ::tcltest::*
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272

273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290










291
292
293
294
295
296
297
    return [dict get $reg $path $key]
}

# Test some of the basics of [clock format]

test clock-1.0 "clock format - wrong # args" {
    list [catch {clock format} msg] $msg $::errorCode
} {1 {wrong # args: should be "clock format clockval ?-format string? ?-gmt boolean? ?-locale LOCALE? ?-timezone ZONE?"} {CLOCK wrongNumArgs}}

test clock-1.1 "clock format - bad time" {
    list [catch {clock format foo} msg] $msg
} {1 {expected integer but got "foo"}}

test clock-1.2 "clock format - bad gmt val" {
    list [catch {clock format 0 -gmt foo} msg] $msg
} {1 {expected boolean value but got "foo"}}

test clock-1.3 "clock format - empty val" {
    clock format 0 -gmt 1 -format ""
} {}

test clock-1.4 "clock format - bad flag" {*}{
    -body {

    list [catch {clock format 0 -oops badflag} msg] $msg $::errorCode
    }
    -match glob
    -result {1 {bad option "-oops": must be -format, -gmt, -locale, or -timezone} {CLOCK badOption -oops}}
}

test clock-1.5 "clock format - bad timezone" {
    list [catch {clock format 0 -format "%s" -timezone :NOWHERE} msg] $msg $::errorCode
} {1 {time zone ":NOWHERE" not found} {CLOCK badTimeZone :NOWHERE}}

test clock-1.6 "clock format - gmt + timezone" {
    list [catch {clock format 0 -timezone :GMT -gmt true} msg] $msg $::errorCode
} {1 {cannot use -gmt and -timezone in same call} {CLOCK gmtWithTimezone}}

test clock-1.7 "clock format - option abbreviations" {
    clock format 0 -g true -f "%Y-%m-%d"
} 1970-01-01











# BEGIN testcases2

# Test formatting of Gregorian year, month, day, all formats
# Formats tested: %b %B %c %Ec %C %EC %d %Od %e %Oe %h %j %J %m %Om %N %x %Ex %y %Oy %Y %EY

test clock-2.1 {conversion of 1872-01-01} {
    clock format -3092556304 \







|















>
|


|














>
>
>
>
>
>
>
>
>
>







251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
    return [dict get $reg $path $key]
}

# Test some of the basics of [clock format]

test clock-1.0 "clock format - wrong # args" {
    list [catch {clock format} msg] $msg $::errorCode
} {1 {wrong # args: should be "clock format clockval|-now ?-format string? ?-gmt boolean? ?-locale LOCALE? ?-timezone ZONE?"} {CLOCK wrongNumArgs}}

test clock-1.1 "clock format - bad time" {
    list [catch {clock format foo} msg] $msg
} {1 {expected integer but got "foo"}}

test clock-1.2 "clock format - bad gmt val" {
    list [catch {clock format 0 -gmt foo} msg] $msg
} {1 {expected boolean value but got "foo"}}

test clock-1.3 "clock format - empty val" {
    clock format 0 -gmt 1 -format ""
} {}

test clock-1.4 "clock format - bad flag" {*}{
    -body {
    # range error message for possible extensions:
    list [catch {clock format 0 -oops badflag} msg] [string range $msg 0 60] $::errorCode
    }
    -match glob
    -result {1 {bad option "-oops": must be -format, -gmt, -locale, -timezone} {CLOCK badOption -oops}}
}

test clock-1.5 "clock format - bad timezone" {
    list [catch {clock format 0 -format "%s" -timezone :NOWHERE} msg] $msg $::errorCode
} {1 {time zone ":NOWHERE" not found} {CLOCK badTimeZone :NOWHERE}}

test clock-1.6 "clock format - gmt + timezone" {
    list [catch {clock format 0 -timezone :GMT -gmt true} msg] $msg $::errorCode
} {1 {cannot use -gmt and -timezone in same call} {CLOCK gmtWithTimezone}}

test clock-1.7 "clock format - option abbreviations" {
    clock format 0 -g true -f "%Y-%m-%d"
} 1970-01-01

test clock-1.8 "clock format -now" {
    # give one second more for test (if on boundary of the current second):
    set n [clock format [clock seconds] -g 1 -f "%s"]
    expr {[clock format -now -g 1 -f "%s"] in [list $n [incr n]]}
} 1

test clock-1.9 "clock arguments: option doubly present" {
    list [catch {clock format 0 -gmt 1 -gmt 0} result] $result
} {1 {bad option "-gmt": doubly present}}

# BEGIN testcases2

# Test formatting of Gregorian year, month, day, all formats
# Formats tested: %b %B %c %Ec %C %EC %d %Od %e %Oe %h %j %J %m %Om %N %x %Ex %y %Oy %Y %EY

test clock-2.1 {conversion of 1872-01-01} {
    clock format -3092556304 \
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565











































































































































18566
18567
18568
18569
18570
18571
18572
} 2147483648

test clock-6.8 {input of seconds} {
    clock scan {9223372036854775807} -format %s -gmt true
} 9223372036854775807

test clock-6.9 {input of seconds - overflow} {
    list [catch {clock scan -9223372036854775809 -format %s -gmt true} result] $result
} {1 {integer value too large to represent}}

test clock-6.10 {input of seconds - overflow} {
    list [catch {clock scan 9223372036854775808 -format %s -gmt true} result] $result
} {1 {integer value too large to represent}}

test clock-6.11 {input of seconds - two values} {
    clock scan {1 2} -format {%s %s} -gmt true
} 2












































































































































test clock-7.1 {Julian Day} {
    clock scan 0 -format %J -gmt true
} -210866803200

test clock-7.2 {Julian Day} {
    clock format [clock scan 2440588 -format %J -gmt true] \







|
|


|
|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
} 2147483648

test clock-6.8 {input of seconds} {
    clock scan {9223372036854775807} -format %s -gmt true
} 9223372036854775807

test clock-6.9 {input of seconds - overflow} {
    list [catch {clock scan -9223372036854775809 -format %s -gmt true} result] $result $::errorCode
} {1 {requested date too large to represent} {CLOCK dateTooLarge}}

test clock-6.10 {input of seconds - overflow} {
    list [catch {clock scan 9223372036854775808 -format %s -gmt true} result] $result $::errorCode
} {1 {requested date too large to represent} {CLOCK dateTooLarge}}

test clock-6.11 {input of seconds - two values} {
    clock scan {1 2} -format {%s %s} -gmt true
} 2

test clock-6.12 {input of unambiguous short locale token (%b)} {
    list [clock scan "12 Ja 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1] \
	 [clock scan "12 Au 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1]
} {979257600 997574400}
test clock-6.13 {input of lowercase locale token (%b)} {
    list [clock scan "12 ja 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1] \
	 [clock scan "12 au 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1]
} {979257600 997574400}
test clock-6.14 {input of uppercase locale token (%b)} {
    list [clock scan "12 JA 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1] \
	 [clock scan "12 AU 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1]
} {979257600 997574400}
test clock-6.15 {input of ambiguous short locale token (%b)} {
    list [catch {
	clock scan "12 J 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1
    } result] $result $errorCode
} {1 {input string does not match supplied format} {CLOCK badInputString}}
test clock-6.16 {input of ambiguous short locale token (%b)} {
    list [catch {
	clock scan "12 Ju 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1
    } result] $result $errorCode
} {1 {input string does not match supplied format} {CLOCK badInputString}}

test clock-6.17 {spaces are always optional in non-strict mode (default)} {
    list [clock scan "2009-06-30T18:30:00+02:00" -format "%Y-%m-%dT%H:%M:%S%z" -gmt 1] \
	 [clock scan "2009-06-30T18:30:00  +02:00" -format "%Y-%m-%dT%H:%M:%S%z" -gmt 1] \
	 [clock scan "2009-06-30T18:30:00Z" -format "%Y-%m-%dT%H:%M:%S%z" -timezone CET] \
	 [clock scan "2009-06-30T18:30:00  Z" -format "%Y-%m-%dT%H:%M:%S%z" -timezone CET]
} {1246379400 1246379400 1246386600 1246386600}

test clock-6.18 {zone token (%z) is optional} {
    list [clock scan "2009-06-30T18:30:00 -01:00" -format "%Y-%m-%dT%H:%M:%S%z" -gmt 1] \
         [clock scan "2009-06-30T18:30:00" -format "%Y-%m-%dT%H:%M:%S%z" -gmt 1] \
	 [clock scan "  2009-06-30T18:30:00  " -format "%Y-%m-%dT%H:%M:%S%z" -gmt 1] \
} {1246390200 1246386600 1246386600}

test clock-6.19 {no token parsing} {
    list [catch { clock scan "%E%O%" -format "%E%O%" }] \
         [catch { clock scan "...%..." -format "...%%..." }]
} {0 0}

test clock-6.20 {special char tokens %n, %t} {
    clock scan "30\t06\t2009\n18\t30" -format "%d%t%m%t%Y%n%H%t%M" -gmt 1
} 1246386600

# Hi, Jeff!
test clock-6.21.0 {Stardate 0 day} {
    list [set d [clock format -757382400 -format "%Q" -gmt 1]] \
         [clock scan $d -format "%Q" -gmt 1]
} [list "Stardate 00000.0" -757382400]
test clock-6.21.1 {Stardate} {
    list [set d [clock format 1482857280 -format "%Q" -gmt 1]] \
         [clock scan $d -format "%Q" -gmt 1]
} [list "Stardate 70986.7" 1482857280]
test clock-6.21.2 {Stardate next time} {
    list [set d [clock format 1482865920 -format "%Q" -gmt 1]] \
         [clock scan $d -format "%Q" -gmt 1]
} [list "Stardate 70986.8" 1482865920]
test clock-6.21.3 {Stardate correct scan over year (leap year, begin, middle and end of the year)} -body {
    set s [clock scan "01.01.2016" -f "%d.%m.%Y" -g 1]
    set s [set i [clock scan [clock format $s -f "%Q" -g 1] -g 1]]
    set wrong {}
    while {[incr i 86400] < $s + 86400*366*2} {
	set d [clock format $i -f "%Q" -g 1]
	set i2 [clock scan $d -f "%Q" -g 1]
	if {$i != $i2} {
	    lappend wrong "$d -- ($i != $i2) -- [clock format $i -g 1]"
	}
    }
    join $wrong \n
} -result {} -cleanup {
    unset -nocomplain wrong i i2 s d
}

test clock-6.22.1 {Greedy match} {
    clock format [clock scan "111" -format "%d%m%y" -gmt 1] -locale en -gmt 1
} {Mon Jan 01 00:00:00 GMT 2001}
test clock-6.22.2 {Greedy match} {
    clock format [clock scan "1111" -format "%d%m%y" -gmt 1] -locale en -gmt 1
} {Thu Jan 11 00:00:00 GMT 2001}
test clock-6.22.3 {Greedy match} {
    clock format [clock scan "11111" -format "%d%m%y" -gmt 1] -locale en -gmt 1
} {Sun Nov 11 00:00:00 GMT 2001}
test clock-6.22.4 {Greedy match} {
    clock format [clock scan "111111" -format "%d%m%y" -gmt 1] -locale en -gmt 1
} {Fri Nov 11 00:00:00 GMT 2011}
test clock-6.22.5 {Greedy match} {
    clock format [clock scan "1 1 1" -format "%d%m%y" -gmt 1] -locale en -gmt 1
} {Mon Jan 01 00:00:00 GMT 2001}
test clock-6.22.6 {Greedy match} {
    clock format [clock scan "111 1" -format "%d%m%y" -gmt 1] -locale en -gmt 1
} {Thu Jan 11 00:00:00 GMT 2001}
test clock-6.22.7 {Greedy match} {
    clock format [clock scan "1 111" -format "%d%m%y" -gmt 1] -locale en -gmt 1
} {Thu Nov 01 00:00:00 GMT 2001}
test clock-6.22.8 {Greedy match} {
    clock format [clock scan "1 11 1" -format "%d%m%y" -gmt 1] -locale en -gmt 1
} {Thu Nov 01 00:00:00 GMT 2001}
test clock-6.22.9 {Greedy match} {
    clock format [clock scan "1 11 11" -format "%d%m%y" -gmt 1] -locale en -gmt 1
} {Tue Nov 01 00:00:00 GMT 2011}
test clock-6.22.10 {Greedy match} {
    clock format [clock scan "11 11 11" -format "%d%m%y" -gmt 1] -locale en -gmt 1
} {Fri Nov 11 00:00:00 GMT 2011}
test clock-6.22.11 {Greedy match} {
    clock format [clock scan "1111 120" -format "%y%m%d %H%M%S" -gmt 1] -locale en -gmt 1
} {Sat Jan 01 01:02:00 GMT 2011}
test clock-6.22.12 {Greedy match} {
    clock format [clock scan "11 1 120" -format "%y%m%d %H%M%S" -gmt 1] -locale en -gmt 1
} {Mon Jan 01 01:02:00 GMT 2001}
test clock-6.22.13 {Greedy match} {
    clock format [clock scan "1 11 120" -format "%y%m%d %H%M%S" -gmt 1] -locale en -gmt 1
} {Mon Jan 01 01:02:00 GMT 2001}
test clock-6.22.14 {Greedy match} {
    clock format [clock scan "111120" -format "%y%m%d%H%M%S" -gmt 1] -locale en -gmt 1
} {Mon Jan 01 01:02:00 GMT 2001}
test clock-6.22.15 {Greedy match} {
    clock format [clock scan "1111120" -format "%y%m%d%H%M%S" -gmt 1] -locale en -gmt 1
} {Sat Jan 01 01:02:00 GMT 2011}
test clock-6.22.16 {Greedy match} {
    clock format [clock scan "11121120" -format "%y%m%d%H%M%S" -gmt 1] -locale en -gmt 1
} {Thu Dec 01 01:02:00 GMT 2011}
test clock-6.22.17 {Greedy match} {
    clock format [clock scan "111213120" -format "%y%m%d%H%M%S" -gmt 1] -locale en -gmt 1
} {Tue Dec 13 01:02:00 GMT 2011}
test clock-6.22.17 {Greedy match (space wins as date-time separator)} {
    clock format [clock scan "1112 13120" -format "%y%m%d %H%M%S" -gmt 1] -locale en -gmt 1
} {Sun Jan 02 13:12:00 GMT 2011}
test clock-6.22.18 {Greedy match (second space wins as date-time separator)} {
    clock format [clock scan "1112 13 120" -format "%y%m%d %H%M%S" -gmt 1] -locale en -gmt 1
} {Tue Dec 13 01:02:00 GMT 2011}
test clock-6.22.19 {Greedy match (space wins as date-time separator)} {
    clock format [clock scan "111 213120" -format "%y%m%d %H%M%S" -gmt 1] -locale en -gmt 1
} {Mon Jan 01 21:31:20 GMT 2001}
test clock-6.22.20 {Greedy match (second space wins as date-time separator)} {
    clock format [clock scan "111 2 13120" -format "%y%m%d %H%M%S" -gmt 1] -locale en -gmt 1
} {Sun Jan 02 13:12:00 GMT 2011}


test clock-7.1 {Julian Day} {
    clock scan 0 -format %J -gmt true
} -210866803200

test clock-7.2 {Julian Day} {
    clock format [clock scan 2440588 -format %J -gmt true] \
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
test clock-10.10 {julian day takes precedence over ccyyddd} {
    list [clock scan {2440588 2000001} -format {%J %Y%j} -gmt true] \
	 [clock scan {2000001 2440588} -format {%Y%j %J} -gmt true]
} {0 0}

# BEGIN testcases11

# Test precedence among yyyymmdd and yyyyddd

test clock-11.1 {precedence of ccyyddd and ccyymmdd} {
    clock scan 19700101002 -format %Y%m%d%j -gmt 1
} 86400
test clock-11.2 {precedence of ccyyddd and ccyymmdd} {
    clock scan 01197001002 -format %m%Y%d%j -gmt 1
} 86400
test clock-11.3 {precedence of ccyyddd and ccyymmdd} {
    clock scan 01197001002 -format %d%Y%m%j -gmt 1
} 86400
test clock-11.4 {precedence of ccyyddd and ccyymmdd} {
    clock scan 00219700101 -format %j%Y%m%d -gmt 1
} 0
test clock-11.5 {precedence of ccyyddd and ccyymmdd} {
    clock scan 19700100201 -format %Y%m%j%d -gmt 1
} 0
test clock-11.6 {precedence of ccyyddd and ccyymmdd} {
    clock scan 01197000201 -format %m%Y%j%d -gmt 1
} 0
test clock-11.7 {precedence of ccyyddd and ccyymmdd} {
    clock scan 01197000201 -format %d%Y%j%m -gmt 1
} 0
test clock-11.8 {precedence of ccyyddd and ccyymmdd} {
    clock scan 00219700101 -format %j%Y%d%m -gmt 1
} 0
test clock-11.9 {precedence of ccyyddd and ccyymmdd} {
    clock scan 19700101002 -format %Y%d%m%j -gmt 1
} 86400
test clock-11.10 {precedence of ccyyddd and ccyymmdd} {
    clock scan 01011970002 -format %m%d%Y%j -gmt 1
} 86400
test clock-11.11 {precedence of ccyyddd and ccyymmdd} {
    clock scan 01011970002 -format %d%m%Y%j -gmt 1
} 86400
test clock-11.12 {precedence of ccyyddd and ccyymmdd} {
    clock scan 00201197001 -format %j%m%Y%d -gmt 1
} 0
test clock-11.13 {precedence of ccyyddd and ccyymmdd} {
    clock scan 19700100201 -format %Y%d%j%m -gmt 1
} 0
test clock-11.14 {precedence of ccyyddd and ccyymmdd} {
    clock scan 01010021970 -format %m%d%j%Y -gmt 1
} 86400
test clock-11.15 {precedence of ccyyddd and ccyymmdd} {
    clock scan 01010021970 -format %d%m%j%Y -gmt 1
} 86400
test clock-11.16 {precedence of ccyyddd and ccyymmdd} {
    clock scan 00201011970 -format %j%m%d%Y -gmt 1
} 0
test clock-11.17 {precedence of ccyyddd and ccyymmdd} {
    clock scan 19700020101 -format %Y%j%m%d -gmt 1
} 0
test clock-11.18 {precedence of ccyyddd and ccyymmdd} {
    clock scan 01002197001 -format %m%j%Y%d -gmt 1
} 0
test clock-11.19 {precedence of ccyyddd and ccyymmdd} {
    clock scan 01002197001 -format %d%j%Y%m -gmt 1
} 0
test clock-11.20 {precedence of ccyyddd and ccyymmdd} {
    clock scan 00201197001 -format %j%d%Y%m -gmt 1
} 0
test clock-11.21 {precedence of ccyyddd and ccyymmdd} {
    clock scan 19700020101 -format %Y%j%d%m -gmt 1
} 0
test clock-11.22 {precedence of ccyyddd and ccyymmdd} {
    clock scan 01002011970 -format %m%j%d%Y -gmt 1
} 0
test clock-11.23 {precedence of ccyyddd and ccyymmdd} {
    clock scan 01002011970 -format %d%j%m%Y -gmt 1
} 0
test clock-11.24 {precedence of ccyyddd and ccyymmdd} {
    clock scan 00201011970 -format %j%d%m%Y -gmt 1
} 0
# END testcases11

# BEGIN testcases12

# Test parsing of ccyyWwwd







|

|

|
|

|
|

|
|


|


|


|


|


|

|
|

|
|

|
|


|


|

|
|

|
|


|


|


|


|


|


|


|


|







21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
test clock-10.10 {julian day takes precedence over ccyyddd} {
    list [clock scan {2440588 2000001} -format {%J %Y%j} -gmt true] \
	 [clock scan {2000001 2440588} -format {%Y%j %J} -gmt true]
} {0 0}

# BEGIN testcases11

# Test precedence yyyymmdd over yyyyddd

test clock-11.1 {precedence of ccyymmdd over ccyyddd} {
    clock scan 19700101002 -format %Y%m%d%j -gmt 1
} 0
test clock-11.2 {precedence of ccyymmdd over ccyyddd} {
    clock scan 01197001002 -format %m%Y%d%j -gmt 1
} 0
test clock-11.3 {precedence of ccyymmdd over ccyyddd} {
    clock scan 01197001002 -format %d%Y%m%j -gmt 1
} 0
test clock-11.4 {precedence of ccyymmdd over ccyyddd} {
    clock scan 00219700101 -format %j%Y%m%d -gmt 1
} 0
test clock-11.5 {precedence of ccyymmdd over ccyyddd} {
    clock scan 19700100201 -format %Y%m%j%d -gmt 1
} 0
test clock-11.6 {precedence of ccyymmdd over ccyyddd} {
    clock scan 01197000201 -format %m%Y%j%d -gmt 1
} 0
test clock-11.7 {precedence of ccyymmdd over ccyyddd} {
    clock scan 01197000201 -format %d%Y%j%m -gmt 1
} 0
test clock-11.8 {precedence of ccyymmdd over ccyyddd} {
    clock scan 00219700101 -format %j%Y%d%m -gmt 1
} 0
test clock-11.9 {precedence of ccyymmdd over ccyyddd} {
    clock scan 19700101002 -format %Y%d%m%j -gmt 1
} 0
test clock-11.10 {precedence of ccyymmdd over ccyyddd} {
    clock scan 01011970002 -format %m%d%Y%j -gmt 1
} 0
test clock-11.11 {precedence of ccyymmdd over ccyyddd} {
    clock scan 01011970002 -format %d%m%Y%j -gmt 1
} 0
test clock-11.12 {precedence of ccyymmdd over ccyyddd} {
    clock scan 00201197001 -format %j%m%Y%d -gmt 1
} 0
test clock-11.13 {precedence of ccyymmdd over ccyyddd} {
    clock scan 19700100201 -format %Y%d%j%m -gmt 1
} 0
test clock-11.14 {precedence of ccyymmdd over ccyyddd} {
    clock scan 01010021970 -format %m%d%j%Y -gmt 1
} 0
test clock-11.15 {precedence of ccyymmdd over ccyyddd} {
    clock scan 01010021970 -format %d%m%j%Y -gmt 1
} 0
test clock-11.16 {precedence of ccyymmdd over ccyyddd} {
    clock scan 00201011970 -format %j%m%d%Y -gmt 1
} 0
test clock-11.17 {precedence of ccyymmdd over ccyyddd} {
    clock scan 19700020101 -format %Y%j%m%d -gmt 1
} 0
test clock-11.18 {precedence of ccyymmdd over ccyyddd} {
    clock scan 01002197001 -format %m%j%Y%d -gmt 1
} 0
test clock-11.19 {precedence of ccyymmdd over ccyyddd} {
    clock scan 01002197001 -format %d%j%Y%m -gmt 1
} 0
test clock-11.20 {precedence of ccyymmdd over ccyyddd} {
    clock scan 00201197001 -format %j%d%Y%m -gmt 1
} 0
test clock-11.21 {precedence of ccyymmdd over ccyyddd} {
    clock scan 19700020101 -format %Y%j%d%m -gmt 1
} 0
test clock-11.22 {precedence of ccyymmdd over ccyyddd} {
    clock scan 01002011970 -format %m%j%d%Y -gmt 1
} 0
test clock-11.23 {precedence of ccyymmdd over ccyyddd} {
    clock scan 01002011970 -format %d%j%m%Y -gmt 1
} 0
test clock-11.24 {precedence of ccyymmdd over ccyyddd} {
    clock scan 00201011970 -format %j%d%m%Y -gmt 1
} 0
# END testcases11

# BEGIN testcases12

# Test parsing of ccyyWwwd
35658
35659
35660
35661
35662
35663
35664
35665
35666
35667
35668
35669
35670
35671
35672
35673
35674
35675








35676
35677
35678
35679
35680
35681
35682
} {Oct 23,1992 15:00 GMT}
test clock-34.8 {clock scan tests} {
    set time [clock scan "Oct 23,1992 15:00" -gmt true]
    clock format $time -format {%b %d,%Y %H:%M GMT} -gmt true
} {Oct 23,1992 15:00 GMT}
test clock-34.9 {clock scan tests} {
    list [catch {clock scan "Jan 12" -bad arg} msg] $msg
} {1 {bad option "-bad", must be -base, -format, -gmt, -locale or -timezone}}
# The following two two tests test the two year date policy
test clock-34.10 {clock scan tests} {
    set time [clock scan "1/1/71" -gmt true]
    clock format $time -format {%b %d,%Y %H:%M GMT} -gmt true
} {Jan 01,1971 00:00 GMT}
test clock-34.11 {clock scan tests} {
    set time [clock scan "1/1/37" -gmt true]
    clock format $time -format {%b %d,%Y %H:%M GMT} -gmt true
} {Jan 01,2037 00:00 GMT}









test clock-34.12 {clock scan, relative times} {
    set time [clock scan "Oct 23, 1992 -1 day"]
    clock format $time -format {%b %d, %Y}
} "Oct 22, 1992"
test clock-34.13 {clock scan, ISO 8601 base date format} {
    set time [clock scan "19921023"]
    clock format $time -format {%b %d, %Y}







|









|
>
>
>
>
>
>
>
>







35809
35810
35811
35812
35813
35814
35815
35816
35817
35818
35819
35820
35821
35822
35823
35824
35825
35826
35827
35828
35829
35830
35831
35832
35833
35834
35835
35836
35837
35838
35839
35840
35841
} {Oct 23,1992 15:00 GMT}
test clock-34.8 {clock scan tests} {
    set time [clock scan "Oct 23,1992 15:00" -gmt true]
    clock format $time -format {%b %d,%Y %H:%M GMT} -gmt true
} {Oct 23,1992 15:00 GMT}
test clock-34.9 {clock scan tests} {
    list [catch {clock scan "Jan 12" -bad arg} msg] $msg
} {1 {bad option "-bad": must be -format, -gmt, -locale, -timezone, or -base}}
# The following two two tests test the two year date policy
test clock-34.10 {clock scan tests} {
    set time [clock scan "1/1/71" -gmt true]
    clock format $time -format {%b %d,%Y %H:%M GMT} -gmt true
} {Jan 01,1971 00:00 GMT}
test clock-34.11 {clock scan tests} {
    set time [clock scan "1/1/37" -gmt true]
    clock format $time -format {%b %d,%Y %H:%M GMT} -gmt true
} {Jan 01,2037 00:00 GMT}
test clock-34.11.1 {clock scan tests: same century switch} {
    set times [clock scan "1/1/37" -gmt true]
} [clock scan "1/1/37" -format "%m/%d/%y" -gmt true]
test clock-34.11.2 {clock scan tests: same century switch} {
    set times [clock scan "1/1/38" -gmt true]
} [clock scan "1/1/38" -format "%m/%d/%y" -gmt true]
test clock-34.11.3 {clock scan tests: same century switch} {
    set times [clock scan "1/1/39" -gmt true]
} [clock scan "1/1/39" -format "%m/%d/%y" -gmt true]
test clock-34.12 {clock scan, relative times} {
    set time [clock scan "Oct 23, 1992 -1 day"]
    clock format $time -format {%b %d, %Y}
} "Oct 22, 1992"
test clock-34.13 {clock scan, ISO 8601 base date format} {
    set time [clock scan "19921023"]
    clock format $time -format {%b %d, %Y}
35791
35792
35793
35794
35795
35796
35797





















35798
35799
35800
35801
35802
35803
35804
    clock format [clock scan "thursday" -base [clock scan 20000112]] \
	    -format {%b %d, %Y}
} "Jan 13, 2000"
test clock-34.40 {clock scan, next day of week} {
    clock format [clock scan "next thursday" -base [clock scan 20000112]] \
	    -format {%b %d, %Y}
} "Jan 20, 2000"






















# weekday specification and base.
test clock-34.41 {2nd monday in november} {
    set res {}
    foreach i {91 92 93 94 95 96} {
      set nov8th [clock scan 11/8/$i]
      set monday [clock scan monday -base $nov8th]







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







35950
35951
35952
35953
35954
35955
35956
35957
35958
35959
35960
35961
35962
35963
35964
35965
35966
35967
35968
35969
35970
35971
35972
35973
35974
35975
35976
35977
35978
35979
35980
35981
35982
35983
35984
    clock format [clock scan "thursday" -base [clock scan 20000112]] \
	    -format {%b %d, %Y}
} "Jan 13, 2000"
test clock-34.40 {clock scan, next day of week} {
    clock format [clock scan "next thursday" -base [clock scan 20000112]] \
	    -format {%b %d, %Y}
} "Jan 20, 2000"
test clock-34.40.1 {clock scan, ordinal month after relative date} {
    # This will fail without the bug fix (clock.tcl), as still missing
    # month/julian day conversion before ordinal month increment
    clock format [ \
        clock scan "5 years 18 months 387 days" -base 0 -gmt 1
    ] -format {%a, %b %d, %Y} -gmt 1 -locale en_US_roman
} "Sat, Jul 23, 1977"
test clock-34.40.2 {clock scan, ordinal month after relative date} {
    # This will fail without the bug fix (clock.tcl), as still missing
    # month/julian day conversion before ordinal month increment
    clock format [ \
        clock scan "5 years 18 months 387 days next Jan" -base 0 -gmt 1
    ] -format {%a, %b %d, %Y} -gmt 1 -locale en_US_roman
} "Mon, Jan 23, 1978"
test clock-34.40.3 {clock scan, day of week after ordinal date} {
    # This will fail without the bug fix (clock.tcl), because the relative
    # week day should be applied after whole date conversion
    clock format [ \
        clock scan "5 years 18 months 387 days next January Fri" -base 0 -gmt 1
    ] -format {%a, %b %d, %Y} -gmt 1 -locale en_US_roman
} "Fri, Jan 27, 1978"

# weekday specification and base.
test clock-34.41 {2nd monday in november} {
    set res {}
    foreach i {91 92 93 94 95 96} {
      set nov8th [clock scan 11/8/$i]
      set monday [clock scan monday -base $nov8th]
35884
35885
35886
35887
35888
35889
35890





35891


















































































35892
35893
35894
35895
35896
35897
35898

test clock-34.52 {more than one ordinal month} {*}{
    -body {clock scan {next January next March}}
    -returnCodes error
    -result {unable to convert date-time string "next January next March": more than one ordinal month in string}
}


























































































# clock seconds
test clock-35.1 {clock seconds tests} {
    expr [clock seconds]+1
    concat {}
} {}
test clock-35.2 {clock seconds tests} {







>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







36064
36065
36066
36067
36068
36069
36070
36071
36072
36073
36074
36075
36076
36077
36078
36079
36080
36081
36082
36083
36084
36085
36086
36087
36088
36089
36090
36091
36092
36093
36094
36095
36096
36097
36098
36099
36100
36101
36102
36103
36104
36105
36106
36107
36108
36109
36110
36111
36112
36113
36114
36115
36116
36117
36118
36119
36120
36121
36122
36123
36124
36125
36126
36127
36128
36129
36130
36131
36132
36133
36134
36135
36136
36137
36138
36139
36140
36141
36142
36143
36144
36145
36146
36147
36148
36149
36150
36151
36152
36153
36154
36155
36156
36157
36158
36159
36160
36161
36162
36163
36164
36165

test clock-34.52 {more than one ordinal month} {*}{
    -body {clock scan {next January next March}}
    -returnCodes error
    -result {unable to convert date-time string "next January next March": more than one ordinal month in string}
}

test clock-34.53.1 {relative from base, date switch} {
    set base [clock scan "12/31/2016 23:59:59" -gmt 1]
    clock format [clock scan "+1 second" \
       -base $base -gmt 1] -gmt 1 -format {%Y-%m-%d %H:%M:%S}
} {2017-01-01 00:00:00}

test clock-34.53.2 {relative time, daylight switch} {
    set base [clock scan "03/27/2016" -timezone CET]
    set res {}
    lappend res [clock format [clock scan "+1 hour" \
       -base $base -timezone CET] -timezone CET -format {%Y-%m-%d %H:%M:%S %Z}]
    lappend res [clock format [clock scan "+2 hour" \
       -base $base -timezone CET] -timezone CET -format {%Y-%m-%d %H:%M:%S %Z}]
} {{2016-03-27 01:00:00 CET} {2016-03-27 03:00:00 CEST}}

test clock-34.53.3 {relative time with day increment / daylight switch} {
    set base [clock scan "03/27/2016" -timezone CET]
    set res {}
    lappend res [clock format [clock scan "+5 day +25 hour" \
       -base [expr {$base - 6*24*60*60}] -timezone CET] -timezone CET -format {%Y-%m-%d %H:%M:%S %Z}]
    lappend res [clock format [clock scan "+5 day +26 hour" \
       -base [expr {$base - 6*24*60*60}] -timezone CET] -timezone CET -format {%Y-%m-%d %H:%M:%S %Z}]
} {{2016-03-27 01:00:00 CET} {2016-03-27 03:00:00 CEST}}

test clock-34.53.4 {relative time with month & day increment / daylight switch} {
    set base [clock scan "03/27/2016" -timezone CET]
    set res {}
    lappend res [clock format [clock scan "next Mar +5 day +25 hour" \
       -base [expr {$base - 35*24*60*60}] -timezone CET] -timezone CET -format {%Y-%m-%d %H:%M:%S %Z}]
    lappend res [clock format [clock scan "next Mar +5 day +26 hour" \
       -base [expr {$base - 35*24*60*60}] -timezone CET] -timezone CET -format {%Y-%m-%d %H:%M:%S %Z}]
} {{2016-03-27 01:00:00 CET} {2016-03-27 03:00:00 CEST}}

test clock-34.54.1 {check date in DST-hole: daylight switch CET -> CEST} {
    set res {}
    # forwards
    set base 1459033200
    for {set i 0} {$i <= 3} {incr i} {
    	set d [clock scan "+$i hour" -base $base -timezone CET]
    	lappend res "$d = [clock format $d -timezone CET -format {%Y-%m-%d %H:%M:%S %Z}]"
    }
    lappend res "#--"
    # backwards
    set base 1459044000
    for {set i 0} {$i <= 3} {incr i} {
    	set d [clock scan "-$i hour" -base $base -timezone CET]
    	lappend res "$d = [clock format $d -timezone CET -format {%Y-%m-%d %H:%M:%S %Z}]"
    }
    set res
} [split [regsub -all {^\n|\n$} {
1459033200 = 2016-03-27 00:00:00 CET
1459036800 = 2016-03-27 01:00:00 CET
1459040400 = 2016-03-27 03:00:00 CEST
1459044000 = 2016-03-27 04:00:00 CEST
#--
1459044000 = 2016-03-27 04:00:00 CEST
1459040400 = 2016-03-27 03:00:00 CEST
1459036800 = 2016-03-27 01:00:00 CET
1459033200 = 2016-03-27 00:00:00 CET
} {}] \n]

test clock-34.54.2 {check date in DST-hole: daylight switch CEST -> CET} {
    set res {}
    # forwards
    set base 1477782000
    for {set i 0} {$i <= 3} {incr i} {
    	set d [clock scan "+$i hour" -base $base -timezone CET]
    	lappend res "$d = [clock format $d -timezone CET -format {%Y-%m-%d %H:%M:%S %Z}]"
    }
    lappend res "#--"
    # backwards
    set base 1477792800
    for {set i 0} {$i <= 3} {incr i} {
    	set d [clock scan "-$i hour" -base $base -timezone CET]
    	lappend res "$d = [clock format $d -timezone CET -format {%Y-%m-%d %H:%M:%S %Z}]"
    }
    set res
} [split [regsub -all {^\n|\n$} {
1477782000 = 2016-10-30 01:00:00 CEST
1477785600 = 2016-10-30 02:00:00 CEST
1477789200 = 2016-10-30 02:00:00 CET
1477792800 = 2016-10-30 03:00:00 CET
#--
1477792800 = 2016-10-30 03:00:00 CET
1477789200 = 2016-10-30 02:00:00 CET
1477785600 = 2016-10-30 02:00:00 CEST
1477782000 = 2016-10-30 01:00:00 CEST
} {}] \n]

# clock seconds
test clock-35.1 {clock seconds tests} {
    expr [clock seconds]+1
    concat {}
} {}
test clock-35.2 {clock seconds tests} {
35919
35920
35921
35922
35923
35924
35925


35926
35927
35928
35929









35930
35931
35932
35933
35934
35935
35936
	    -format %m.%Y
} "05.2001"

test clock-37.1 {%s gmt testing} {
    set s [clock seconds]
    set a [clock format $s -format %s -gmt 0]
    set b [clock format $s -format %s -gmt 1]


    # %s, being the difference between local and Greenwich, does not
    # depend on the time zone.
    set c [expr {$b-$a}]
} {0}










test clock-38.1 {regression - convertUTCToLocalViaC - east of Greenwich} \
    -setup {
	if { [info exists env(TZ)] } {
	    set oldTZ $env(TZ)
	}
	set env(TZ) CET-01:00CEST-02:00,M3.5.0/02:00,M10.5.0/03:00







>
>


|
|
>
>
>
>
>
>
>
>
>







36186
36187
36188
36189
36190
36191
36192
36193
36194
36195
36196
36197
36198
36199
36200
36201
36202
36203
36204
36205
36206
36207
36208
36209
36210
36211
36212
36213
36214
	    -format %m.%Y
} "05.2001"

test clock-37.1 {%s gmt testing} {
    set s [clock seconds]
    set a [clock format $s -format %s -gmt 0]
    set b [clock format $s -format %s -gmt 1]
    set c [clock scan $s -format %s -gmt 0]
    set d [clock scan $s -format %s -gmt 1]
    # %s, being the difference between local and Greenwich, does not
    # depend on the time zone.
    list [expr {$b-$a}] [expr {$d-$c}]
} {0 0}
test clock-37.2 {%Es gmt testing} {
    set s [clock seconds]
    set a [clock format $s -format %Es -timezone CET]
    set b [clock format $s -format %Es -gmt 1]
    set c [clock scan $s -format %Es -timezone CET]
    set d [clock scan $s -format %Es -gmt 1]
    # %Es depend on the time zone (local seconds instead of posix seconds).
    list [expr {$b-$a}] [expr {$d-$c}]
} {-3600 3600}

test clock-38.1 {regression - convertUTCToLocalViaC - east of Greenwich} \
    -setup {
	if { [info exists env(TZ)] } {
	    set oldTZ $env(TZ)
	}
	set env(TZ) CET-01:00CEST-02:00,M3.5.0/02:00,M10.5.0/03:00