1#
2# clock.test
3#
4# Tests for deprecated TclX clock commands: getclock, fmtclock and
5# convertclock.
6#---------------------------------------------------------------------------
7# Copyright 1992-1999 Karl Lehenbauer and Mark Diekhans.
8#
9# Permission to use, copy, modify, and distribute this software and its
10# documentation for any purpose and without fee is hereby granted, provided
11# that the above copyright notice appear in all copies.  Karl Lehenbauer and
12# Mark Diekhans make no representations about the suitability of this
13# software for any purpose.  It is provided "as is" without express or
14# implied warranty.
15#------------------------------------------------------------------------------
16# $Id: clock.test,v 1.1 2001/10/24 23:31:49 hobbs Exp $
17#------------------------------------------------------------------------------
18#
19
20# FIX: Currently strftime use of %Z (or any unknown format spec) causes core
21# dumps on MS VC++.  Remove constraints when base Tcl works around the problem.
22
23if [cequal [info procs Test] {}] {source testlib.tcl}
24eval $SAVED_UNKNOWN
25
26# Try getclock, hard to test the result, make sure its a number
27
28Test clock-1.1 {getclock tests} {
29    expr [getclock]+1
30    concat {}
31} 0 {}
32
33Test clock-1.2 {getclock tests} {
34    getclock 1990
35} 1 {called "getclock" with too many arguments}
36
37# Test fmtclock
38
39Test clock-2.1 {fmtclock tests} {
40    set clockval 657687766
41    fmtclock $clockval {%a %b %d %I:%M:%S %p %Y} GMT
42} 0 {Sun Nov 04 03:02:46 AM 1990}
43
44Test clock-2.2 {fmtclock tests} {
45    fmtclock
46} 1 {no value given for parameter "clockval" to "fmtclock"}
47
48set large [replicate XYZabc 500]
49Test clock-2.2 {fmtclock tests} {
50    set clockval 657687766
51    fmtclock $clockval "%a %b %d %I:%M:%S %p %Y $large" GMT
52} 0 "Sun Nov 04 03:02:46 AM 1990 $large"
53unset large
54
55# Test convertclock
56
57Test clock-3.1 {convertclock tests} {
58    convertclock
59} 1 {no value given for parameter "dateString" to "convertclock"}
60
61Test clock-3.2 {convertclock tests} {
62    fmtclock [convertclock "14 Feb 92" GMT] {%m/%d/%y %I:%M:%S %p} GMT
63} 0 {02/14/92 12:00:00 AM}
64
65Test clock-3.3 {convertclock tests} {
66    fmtclock [convertclock "Feb 14, 1992 12:20 PM" GMT] {%m/%d/%y %I:%M:%S %p} GMT
67} 0 {02/14/92 12:20:00 PM}
68
69Test clock-3.5 {convertclock tests} {
70    fmtclock [convertclock "Feb 14, 1992 12:20 PM" {GMT} 319363200] {%m/%d/%y %I:%M:%S %p} GMT
71} 0 {02/14/92 12:20:00 PM}
72
73Test clock-3.6 {convertclock tests} {
74    set clock [convertclock "Oct 23,1992 15:00"]
75    fmtclock $clock {%b %d,%Y %H:%M}
76} 0 {Oct 23,1992 15:00}
77
78Test clock-3.7 {convertclock tests} {
79    set clock [convertclock "Oct 23,1992 15:00 GMT"]
80    fmtclock $clock {%b %d,%Y %H:%M GMT} GMT
81} 0 {Oct 23,1992 15:00 GMT}
82
83
84Test clock-3.8 {convertclock tests} {
85    set clock [convertclock "Oct 23,1992 15:00" GMT]
86    fmtclock $clock {%b %d,%Y %H:%M GMT} GMT
87} 0 {Oct 23,1992 15:00 GMT}
88
89# Test if local timezone works when not explicitly specified.
90
91Test clock-3.9 {convertclock tests} {
92    # WARNING: This test might fail if your symbolic timezone name conflicts
93    # with names use in other parts of the world or if the symbolic zone is
94    # returns an incorrect value.
95    #
96    #  o EST for Australian Eastern Summer Time.
97    #  o EST for Australian Eastern Standard Time.
98    #  o On some systems, a "TZ=GMT+2" results in strftime returning a
99    #    time zone of just "GMT".
100    #  
101    # Don't worry about these failures.
102
103    set clock [getclock]
104    set ourzone [fmtclock $clock %Z]
105    set intime [fmtclock $clock {%a %h %d %T %Y}]
106
107    set cnv1 [convertclock $intime]
108    set cnv2 [convertclock "$intime $ourzone"]
109    if {$cnv1 == $cnv2} {
110        concat OK
111    } else {
112        error "different resulting times: $cnv1, $cnv2"
113    }
114} 0 OK {tempNotPc}
115
116set fmt {%m/%d/%y %I:%M:%S %p}
117foreach hour {01 02 03 04 05 06 07 08 09 10 11 12} {
118   foreach min {00 01 59} {
119       foreach med {AM PM} {
120           Test clock-4.0 {convertclock tests} {
121                fmtclock [convertclock "1/1/72 $hour:$min:00 $med"] $fmt
122           } 0 "01/01/72 $hour:$min:00 $med"
123
124           Test clock-4.1 {convertclock tests} {
125                fmtclock [convertclock "1/1/72 $hour:$min:00 $med" GMT] $fmt GMT
126           } 0 "01/01/72 $hour:$min:00 $med" {unixOnly}
127       }
128   }
129}
130
131rename unknown {}
132
133
134
135
136