home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / tcl / tcl+tk+t / tclx7.3bl / tclx7 / tclX7.3b / tests / clock.test < prev    next >
Encoding:
Text File  |  1994-07-16  |  3.6 KB  |  115 lines

  1. #
  2. # clock.test
  3. #
  4. # Tests for the getclock, fmtclock and convertclock commands.
  5. #---------------------------------------------------------------------------
  6. # Copyright 1992-1994 Karl Lehenbauer and Mark Diekhans.
  7. #
  8. # Permission to use, copy, modify, and distribute this software and its
  9. # documentation for any purpose and without fee is hereby granted, provided
  10. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  11. # Mark Diekhans make no representations about the suitability of this
  12. # software for any purpose.  It is provided "as is" without express or
  13. # implied warranty.
  14. #------------------------------------------------------------------------------
  15. # $Id: clock.test,v 4.0 1994/07/16 05:24:34 markd Rel $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. if {[info procs test] != "test"} then {source testlib.tcl}
  20.  
  21. # Try getclock, hard to test the result, make sure its a number
  22.  
  23. Test clock-1.1 {getclock tests} {
  24.     expr [getclock]+1
  25.     concat {}
  26. } 0 {}
  27.  
  28. Test clock-1.2 {getclock tests} {
  29.     getclock 1990
  30. } 1 {wrong # args: getclock}
  31.  
  32. # Test fmtclock
  33.  
  34. Test clock-2.1 {fmtclock tests} {
  35.     set clockval 657687766
  36.     fmtclock $clockval {%a %b %d %I:%M:%S %p %Y} GMT
  37. } 0 {Sun Nov 04 03:02:46 AM 1990}
  38.  
  39. Test clock-2.2 {fmtclock tests} {
  40.     fmtclock
  41. } 1 {wrong # args: fmtclock clockval ?format? ?GMT|{}?}
  42.  
  43. # Test convertclock
  44.  
  45. Test clock-3.1 {convertclock tests} {
  46.     convertclock
  47. } 1 {wrong # args: convertclock dateString ?GMT|{}? ?baseclock?}
  48.  
  49. Test clock-3.2 {convertclock tests} {
  50.     fmtclock [convertclock "14 Feb 92" GMT] {%m/%d/%y %I:%M:%S %p} GMT
  51. } 0 {02/14/92 12:00:00 AM}
  52.  
  53. Test clock-3.3 {convertclock tests} {
  54.     fmtclock [convertclock "Feb 14, 1992 12:20 PM" GMT] {%m/%d/%y %I:%M:%S %p} GMT
  55. } 0 {02/14/92 12:20:00 PM}
  56.  
  57. Test clock-3.5 {convertclock tests} {
  58.     fmtclock [convertclock "Feb 14, 1992 12:20 PM" {GMT} 319363200] {%m/%d/%y %I:%M:%S %p} GMT
  59. } 0 {02/14/92 12:20:00 PM}
  60.  
  61. Test clock-3.6 {convertclock tests} {
  62.     set clock [convertclock "Oct 23,1992 15:00"]
  63.     fmtclock $clock {%b %d,%Y %H:%M}
  64. } 0 {Oct 23,1992 15:00}
  65.  
  66. Test clock-3.7 {convertclock tests} {
  67.     set clock [convertclock "Oct 23,1992 15:00 GMT"]
  68.     fmtclock $clock {%b %d,%Y %H:%M GMT} GMT
  69. } 0 {Oct 23,1992 15:00 GMT}
  70.  
  71.  
  72. Test clock-3.8 {convertclock tests} {
  73.     set clock [convertclock "Oct 23,1992 15:00" GMT]
  74.     fmtclock $clock {%b %d,%Y %H:%M GMT} GMT
  75. } 0 {Oct 23,1992 15:00 GMT}
  76.  
  77.  
  78. # Test if local timezone works when not explicitly specified.
  79.  
  80. Test clock-3.9 {convertclock tests} {
  81.     # WARNING: This test might fail if your symbolic timezone name conflicts
  82.     # with names use in other parts of the world or if the symbolic zone is
  83.     # returns an incorrect value.
  84.     #
  85.     #  o EST for Australian Eastern Summer Time.
  86.     #  o EST for Australian Eastern Standard Time.
  87.     #  o On some systems, a "TZ=GMT+2" results in strftime returning a
  88.     #    time zone of just "GMT".
  89.     #  
  90.     # Don't worry about these failures.
  91.  
  92.     set clock [getclock]
  93.     set ourzone [fmtclock $clock %Z]
  94.     set intime [fmtclock $clock {%a %h %d %T %Y}]
  95.  
  96.     set cnv1 [convertclock $intime]
  97.     set cnv2 [convertclock "$intime $ourzone"]
  98.     expr {$cnv1 == $cnv2}
  99. } 0 1
  100.  
  101. set fmt {%m/%d/%y %I:%M:%S %p}
  102. foreach hour {01 02 03 04 05 06 07 08 09 10 11 12} {
  103.    foreach min {00 01 59} {
  104.        foreach med {AM PM} {
  105.            Test clock-4.0 {convertclock tests} {
  106.                 fmtclock [convertclock "1/1/72 $hour:$min:00 $med"] $fmt
  107.            } 0 "01/01/72 $hour:$min:00 $med"
  108.  
  109.            Test clock-4.1 {convertclock tests} {
  110.                 fmtclock [convertclock "1/1/72 $hour:$min:00 $med" GMT] $fmt GMT
  111.            } 0 "01/01/72 $hour:$min:00 $med"
  112.        }
  113.    }
  114. }
  115.