📄 clock.test
字号:
# Commands covered: clock## 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) 1995-1998 Sun Microsystems, Inc.# Copyright (c) 1998-1999 by Scriptics Corporation.## See the file "license.terms" for information on usage and redistribution# of this file, and for a DISCLAIMER OF ALL WARRANTIES.## RCS: @(#) $Id: clock.test,v 1.22 2003/02/01 21:27:55 kennykb Exp $set env(LC_TIME) POSIXif {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest namespace import -force ::tcltest::*}test clock-1.1 {clock tests} { list [catch {clock} msg] $msg} {1 {wrong # args: should be "clock option ?arg ...?"}}test clock-1.2 {clock tests} { list [catch {clock foo} msg] $msg} {1 {bad option "foo": must be clicks, format, scan, or seconds}}# clock clickstest clock-2.1 {clock clicks tests} { expr [clock clicks]+1 concat {}} {}test clock-2.2 {clock clicks tests} { set start [clock clicks] after 10 set end [clock clicks] expr "$end > $start"} {1}test clock-2.3 {clock clicks tests} { list [catch {clock clicks foo} msg] $msg} {1 {bad switch "foo": must be -milliseconds}}test clock-2.4 {clock clicks tests} { expr [clock clicks -milliseconds]+1 concat {}} {}test clock-2.5 {clock clicks tests, millisecond timing test} { set start [clock clicks -milli] after 10 set end [clock clicks -milli] # 60 msecs seems to be the max time slice under Windows 95/98 expr {($end > $start) && (($end - $start) <= 60)}} {1}test clock-2.6 {clock clicks, milli with too much abbreviation} { list [catch { clock clicks {} } msg] $msg} {1 {bad switch "": must be -milliseconds}}test clock-2.7 {clock clicks, milli with too much abbreviation} { list [catch { clock clicks - } msg] $msg} {1 {bad switch "-": must be -milliseconds}}# clock formattest clock-3.1 {clock format tests} {unixOnly} { set clockval 657687766 clock format $clockval -format {%a %b %d %I:%M:%S %p %Y} -gmt true} {Sun Nov 04 03:02:46 AM 1990}test clock-3.2 {clock format tests} { # TCL_USE_TIMEZONE_VAR catch {set oldtz $env(TZ)} set env(TZ) PST set x {} append x [clock format 863800000 -format %Z -gmt 1] append x [set env(TZ)] catch {unset env(TZ); set env(TZ) $oldtz} set x} {GMTPST}test clock-3.3 {clock format tests} { # tzset() under Borland doesn't seem to set up tzname[] for local # timezone, which caused "clock format" to think that %Z was an invalid # string. Don't care about answer, just that test runs w/o error. clock format 863800000 -format %Z set x {}} {}test clock-3.4 {clock format tests} { # tzset() under Borland doesn't seem to set up tzname[] for gmt timezone. # tzset() under MSVC has the following weird observed behavior: # First time we call "clock format [clock seconds] -format %Z -gmt 1" # we get "GMT", but on all subsequent calls we get the current time # zone string, even though env(TZ) is GMT and the variable _timezone # is 0. set x {} append x [clock format 863800000 -format %Z -gmt 1] append x [clock format 863800000 -format %Z -gmt 1]} {GMTGMT}test clock-3.5 {clock format tests} { list [catch {clock format} msg] $msg} {1 {wrong # args: should be "clock format clockval ?-format string? ?-gmt boolean?"}}test clock-3.6 {clock format tests} { list [catch {clock format foo} msg] $msg} {1 {expected integer but got "foo"}}test clock-3.7 {clock format tests} {unixOrPc} { set clockval 657687766 clock format $clockval -format "%a %b %d %I:%M:%S %p %Y" -gmt true} "Sun Nov 04 03:02:46 AM 1990"test clock-3.8 {clock format tests} { list [catch {clock format a b c d e g} msg] $msg} {1 {wrong # args: should be "clock format clockval ?-format string? ?-gmt boolean?"}}test clock-3.9 {clock format tests} {unixOrPc nonPortable} { set clockval -1 clock format $clockval -format "%a %b %d %I:%M:%S %p %Y" -gmt true} "Wed Dec 31 11:59:59 PM 1969"test clock-3.10 {clock format tests} { list [catch {clock format 123 -bad arg} msg] $msg} {1 {bad switch "-bad": must be -format or -gmt}}test clock-3.11 {clock format tests} { clock format 123 -format "x"} xtest clock-3.12 {clock format tests} { clock format 123 -format ""} ""test clock-3.13 {clock format with non-ASCII character in the format string} { set oldenc [encoding system] encoding system iso8859-1 set res [clock format 0 -format \u00c4] encoding system $oldenc unset oldenc set res} "\u00c4"# clock scantest clock-4.1 {clock scan tests} { list [catch {clock scan} msg] $msg} {1 {wrong # args: should be "clock scan dateString ?-base clockValue? ?-gmt boolean?"}}test clock-4.2 {clock scan tests} { list [catch {clock scan "bad-string"} msg] $msg} {1 {unable to convert date-time string "bad-string"}}test clock-4.3 {clock scan tests} { clock format [clock scan "14 Feb 92" -gmt true] \ -format {%m/%d/%y %I:%M:%S %p} -gmt true} {02/14/92 12:00:00 AM}test clock-4.4 {clock scan tests} { clock format [clock scan "Feb 14, 1992 12:20 PM" -gmt true] \ -format {%m/%d/%y %I:%M:%S %p} -gmt true} {02/14/92 12:20:00 PM}test clock-4.5 {clock scan tests} { clock format \ [clock scan "Feb 14, 1992 12:20 PM" -base 319363200 -gmt true] \ -format {%m/%d/%y %I:%M:%S %p} -gmt true} {02/14/92 12:20:00 PM}test clock-4.6 {clock scan tests} { set time [clock scan "Oct 23,1992 15:00"] clock format $time -format {%b %d,%Y %H:%M}} {Oct 23,1992 15:00}test clock-4.7 {clock scan tests} { set time [clock scan "Oct 23,1992 15:00 GMT"] clock format $time -format {%b %d,%Y %H:%M GMT} -gmt true} {Oct 23,1992 15:00 GMT}test clock-4.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-4.9 {clock scan tests} { list [catch {clock scan "Jan 12" -bad arg} msg] $msg} {1 {bad switch "-bad": must be -base or -gmt}}# The following two two tests test the two year date policytest clock-4.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-4.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-4.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-4.13 {clock scan, ISO 8601 base date format} { set time [clock scan "19921023"] clock format $time -format {%b %d, %Y}} "Oct 23, 1992"test clock-4.14 {clock scan, ISO 8601 expanded date format} { set time [clock scan "1992-10-23"] clock format $time -format {%b %d, %Y}} "Oct 23, 1992"test clock-4.15 {clock scan, DD-Mon-YYYY format} { set time [clock scan "23-Oct-1992"] clock format $time -format {%b %d, %Y}} "Oct 23, 1992"test clock-4.16 {clock scan, ISO 8601 point in time format} { set time [clock scan "19921023T235959"] clock format $time -format {%b %d, %Y %H:%M:%S}} "Oct 23, 1992 23:59:59"test clock-4.17 {clock scan, ISO 8601 point in time format} { set time [clock scan "19921023 235959"] clock format $time -format {%b %d, %Y %H:%M:%S}} "Oct 23, 1992 23:59:59"test clock-4.18 {clock scan, ISO 8601 point in time format} { set time [clock scan "19921023T000000"] clock format $time -format {%b %d, %Y %H:%M:%S}} "Oct 23, 1992 00:00:00"# CLOCK SCAN REAL TESTS# We use 5am PST, 31-12-1999 as the base for these scans because irrespective# of your local timezone it should always give us times on December 31, 1999set 5amPST 946645200test clock-4.18 {clock scan, number meridian} { set t1 [clock scan "5 am" -base $5amPST -gmt true] set t2 [clock scan "5 pm" -base $5amPST -gmt true] set t3 [clock scan "5 a.m." -base $5amPST -gmt true] set t4 [clock scan "5 p.m." -base $5amPST -gmt true] list \ [clock format $t1 -format {%b %d, %Y %H:%M:%S} -gmt true] \ [clock format $t2 -format {%b %d, %Y %H:%M:%S} -gmt true] \ [clock format $t3 -format {%b %d, %Y %H:%M:%S} -gmt true] \ [clock format $t4 -format {%b %d, %Y %H:%M:%S} -gmt true]} [list "Dec 31, 1999 05:00:00" "Dec 31, 1999 17:00:00" \ "Dec 31, 1999 05:00:00" "Dec 31, 1999 17:00:00"]test clock-4.19 {clock scan, number:number meridian} { clock format [clock scan "5:30 pm" -base $5amPST -gmt true] \ -format {%b %d, %Y %H:%M:%S} -gmt true} "Dec 31, 1999 17:30:00"test clock-4.20 {clock scan, number:number-timezone} { clock format [clock scan "00:00-0800" -gmt true -base $5amPST] \ -format {%b %d, %Y %H:%M:%S} -gmt true} "Dec 31, 1999 08:00:00"test clock-4.21 {clock scan, number:number:number o_merid} { clock format [clock scan "8:00:00" -gmt true -base $5amPST] \ -format {%b %d, %Y %H:%M:%S} -gmt true} "Dec 31, 1999 08:00:00"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -