// TimeTest.bcpl
// Copyright Xerox Corporation 1979

// Bldr TimeTest TimeConvB TimeConvA TimeIO


external
[
Ws; WRITEUDT; WEEKDAY; DoubleAdd; Gets; MoveBlock; Wns
UNPACKDT; PACKDT; ReadCalendar
dsp; keys
]

let Test() be
[
let time = vec 2
ReadCalendar(time)
let negative = false
   [
   let utv = vec 6
   UNPACKDT(time, utv)
   Ws("*n ")
   WRITEUDT(dsp, utv, true)
   Ws(" (")
   Ws(selecton WEEKDAY(time) into
      [
      case 0: "Monday"
      case 1: "Tuesday"
      case 2: "Wednesday"
      case 3: "Thursday"
      case 4: "Friday"
      case 5: "Saturday"
      case 6: "Sunday"
      ])
   Ws(")")
   let check = vec 2
   let c = PACKDT(utv, check, true)
   test c eq 0
      ifnot [ Ws(" -- PACKDT failed, code = "); Wns(dsp, c) ]
      ifso if time!0 ne check!0 % time!1 ne check!1 then
         [
         Ws("*n  -- PACKDT incorrect:  good = ")
         Wns(dsp, time!0, 6, 10); Wns(dsp, time!1, 6, 10)
         Ws(", bad = ")
         Wns(dsp, check!0, 6, 10); Wns(dsp, check!1, 6, 10)
         ]
   let d = nil
   switchon Gets(keys) into
      [
      case $S: case $s:
         [ d = table [ 0; 1 ]; break ]
      case $M: case $m:
         [ d = table [ 0; 60 ]; break ]
      case $H: case $h:
         [ d = table [ 0; 60*60 ]; break ]
      case $D: case $d:
         [ d = table [ 1; 20864 ]; break ]
      case $3:
         [ d = table [ 39; -29440 ]; break ]
      case $+:
         [ negative = false; endcase ]
      case $-:
         [ negative = true; endcase ]
      case $Q: case $q:
         finish
      ] repeat
   let v = vec 2
   MoveBlock(v, d, 2)
   if negative then
      [
      v!1 = -v!1
      v!0 = (v!1 eq 0? -v!0, not v!0)
      ]
   DoubleAdd(time, v)
   ] repeat
]