home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / QTIME.ZIP / QTIME.CMD
OS/2 REXX Batch file  |  1991-07-06  |  5KB  |  139 lines

  1. /* Displays or stacks time in real English, also chimes.            */
  2. /* Arguments:  PUSH           pushes single result line onto stack. */
  3. /*             TEST hh:mm:ss  runs with specified test time.        */
  4. /* Mike Cowlishaw (MFC at VENTA)   1979                             */
  5.  
  6.  
  7.    Parse source  . . program .       /* get my real name */
  8.    Parse upper arg  arg rest         /* get arguments    */
  9.    if arg='?' then do
  10.      call tell                       /* say what we do */
  11.      parse var rest arg rest         /* remove "?" */
  12.      end
  13.  
  14.    stack=0    /* flag to say whether pushing or saying */
  15.    c8=time()  /* Normally use the time Now */
  16.  
  17.    /* Detect and handle PUSH option */
  18.    if arg='PUSH' then do
  19.      stack=1                         /* set flag to indicate request */
  20.      parse var rest arg rest         /*  .. and remove the word */
  21.      end
  22.  
  23.    /* Detect and handle TEST option (must follow PUSH) */
  24.    if arg='TEST' then parse var rest c8 arg rest  /* set c8 and remove */
  25.  
  26.    /* Now check for extraneous (or unrecognised) args */
  27.    if arg<>'' then do
  28.      if rest='' then do; plural='';  own='has';  end  /* grammar.. */
  29.                 else do; plural='s'; own='have'; end
  30.      say 'The extra argument'plural '"'space(arg rest)'"',
  31.          'that you gave to' program own 'been ignored.'
  32.      end
  33.  
  34.    /************** OK, off we go... ***************/
  35.    ot="It's"
  36.  
  37.    hr=substr(c8,1,2)+0        /* extract hours, mins, secs.. */
  38.    mn=substr(c8,4,2)
  39.    sc=substr(c8,7,2)
  40.  
  41.    h.1 = 'one' ;  h.2 = 'two';  h.3 = 'three';   h.4 = 'four'
  42.    h.5 = 'five';  h.6 = 'six';  h.7 = 'seven';   h.8 = 'eight'
  43.    h.9 = 'nine';  h.10= 'ten';  h.11= 'eleven';  h.12= 'twelve'
  44.  
  45.    if sc>29 then mn=mn+1      /* round up mins */
  46.    if mn>32 then hr=hr+1      /* something to.. */
  47.  
  48.    mod=mn//5                  /* find 5-minute bracket */
  49.    select
  50.      when mod=0 then nop      /* exact */
  51.      when mod=1 then ot=ot 'just gone'
  52.      when mod=2 then ot=ot 'just after'
  53.      when mod=3 then ot=ot 'nearly'
  54.      when mod=4 then ot=ot 'almost'
  55.      end                      /* select */
  56.  
  57.    mn=mn+2                    /* round up */
  58.    if hr//12=0 & mn//60<=4
  59.     then signal midnoon       /* special case noon and midnight */
  60.    mn=mn-(mn//5)              /* to nearest 5 mins */
  61.    if hr>12
  62.     then hr=hr-12             /* get rid of 24-hour clock */
  63.     else
  64.      if hr=0 then hr=12       /* cater for midnight */
  65.  
  66.    select
  67.      when mn=0  then nop      /* add O'clock later */
  68.      when mn=60 then mn=0
  69.      when mn= 5 then ot=ot 'five past'
  70.      when mn=10 then ot=ot 'ten past'
  71.      when mn=15 then ot=ot 'a quarter past'
  72.      when mn=20 then ot=ot 'twenty past'
  73.      when mn=25 then ot=ot 'twenty-five past'
  74.      when mn=30 then ot=ot 'half past'
  75.      when mn=35 then ot=ot 'twenty-five to'
  76.      when mn=40 then ot=ot 'twenty to'
  77.      when mn=45 then ot=ot 'a quarter to'
  78.      when mn=50 then ot=ot 'ten to'
  79.      when mn=55 then ot=ot 'five to'
  80.      end
  81.    ot=ot h.hr                    /* add the hour number */
  82.    if mn=0 then ot=ot "o'clock"  /* and O'clock if exact */
  83.    ot=ot'.'                      /* and the correct punctuation */
  84.  
  85.    /* Now stack or display the result */
  86.    if \stack then do
  87.      if mod=0 & mn//15=0 then call chime /* only if displaying */
  88.      say; say ot; say
  89.      end
  90.     else push ot
  91.    exit
  92.  
  93. /* Special-case Midnight and Noon */
  94. MIDNOON:
  95.    if hr=12 then ot=ot 'Noon.'
  96.             else ot=ot 'Midnight.'
  97.    if \stack then do
  98.      hr=12
  99.      if mn//60=2 then do
  100.        mn=0
  101.        call chime
  102.        end
  103.      say; say ot; say
  104.      end
  105.     else push ot
  106.    exit
  107.  
  108. /* "Chime" the hours or quarters */
  109. CHIME:
  110.    /* Give chimes */
  111.    if mn//60=0 then /* hourly chime */ do
  112.      chime='Bong'
  113.      num=hr
  114.      end
  115.     else do         /* quarterly tinkles */
  116.      chime='Ding-Dong'
  117.      num=mn%15
  118.      end
  119.    say; say ot
  120.    ot='('chime      /* Parenthesis and first chime */
  121.    do num-1         /* Add the remainder of chiming sounds ... */
  122.      ot=ot||',' chime
  123.      end
  124.    ot=ot||'!)'      /* ... and final punctuation and parenthesis */
  125.    return /* from chime */
  126.  
  127. TELL:
  128.  say
  129.  say program 'will query the time and display or return it in English.'
  130.  say 'Call without any arguments to display the time, or with "PUSH"'
  131.  say '  to push the time-string onto the Stack (without blank lines).'
  132.  say program 'will "chime" at the quarter-hours and on the hours, but'
  133.  say '  the chimes are also not placed on the stack.'
  134.  say
  135.  say 'English (British) idioms are used in this program.'
  136.  return
  137.  
  138. /* Mike Cowlishaw,  December 1979 - July 1983                        */
  139.