fix remapping behavior. Remapping is only necessary if we are rendering on the workbe...
[AROS-Contrib.git] / rexx / progs / qt.r
blob925cc9d2e3c8751d006dada4fe032d42e907ca2d
1 /*----------------------------------------------------------*/
2 /* Mike Cowlishaw, December 1979 - January 1985 */
3 /*----------------------------------------------------------*/
4 /* QT. This program displays the time in natural English. */
5 /* Two argument strings may be supplied. If "?" is given */
6 /* as the first argument then the program displays a */
7 /* description of itself. If a second argument is supplied */
8 /* it is used as a test value to check the operation of the */
9 /* program. This second value must be a time in the format */
10 /* HH:MM:SS, and does not have its syntax checked. */
11 /*----------------------------------------------------------*/
13 /*------------ First process the argument strings ----------*/
14 parse arg parm . /* get the argument strings */
15 select
16 when parm="?" then call tell /* say what we do */
17 when parm="" then nop /* OK (no first argument) */
19 otherwise
20 say 'The only valid parameter to QT is "?". The argument'
21 say 'that you supplied ("'parm'") has been ignored.'
22 call tell /* usually helpful to describe the program */
24 end
26 testtime = parm
27 if testtime='' then now=time() /* default - use time now */
28 else now=testtime /* caller gave test value */
31 /*------------ Now start processing in earnest -------------*/
32 /* Nearness phrases - using a compound variable as example */
33 near.0='' /* exact */
34 near.1=' just gone'; near.2=' just after' /* after */
35 near.3=' nearly'; near.4=' almost' /* before */
37 /* Extract the hours, minutes, and seconds from the time. */
38 parse var now hour':'min':'sec
40 if sec>29 then min=min+1 /* round up minutes */
41 mod=min//5 /* where we are in 5 minute bracket */
42 out="It's"near.mod /* start building the result */
43 if min>32 then hour=hour+1 /* we are T0 the hour */
44 min=min+2 /* shift minutes to straddle a 5-minute point */
46 /* Now special-case the result fro Noon and Midnight hours */
47 if hour//12=0 & min//60<=4 then do
48 if hour=12 then say out 'Noon.'
49 else say out 'Midnight.'
50 /* we are finished here */
51 exit
52 end
54 min=min-(min//5) /* find nearest 5 mins */
55 if hour>12
56 then hour=hour-12 /* get rid of 24-hour clock */
57 else
58 if hour=0 then hour=12 /* and allow for midnight */
60 /* Determine the phrase to use for each 5-minute segment */
61 select
62 when min= 0 then nop /* add "o'clock" later */
63 when min=60 then min=0 /* ditto */
64 when min= 5 then out=out 'five past'
65 when min=10 then out=out 'ten past'
66 when min=15 then out=out 'a quarter past'
67 when min=20 then out=out 'twenty past'
68 when min=25 then out=out 'twenty-five past'
69 when min=30 then out=out 'half past'
70 when min=35 then out=out 'twenty-five to'
71 when min=40 then out=out 'twenty to'
72 when min=45 then out=out 'a quarter to'
73 when min=50 then out=out 'ten to'
74 when min=55 then out=out 'five to'
75 end
77 numbers='one two three four five six', /* (continuation) */
78 'seven eight nine ten eleven twelve'
79 out=out word(numbers,hour) /* add the hour number */
80 if min=0 then out=out "o'clock" /* .. and o'clock if exact */
82 say out'.' /* display the final result */
83 exit
85 /*----------------------------------------------------------*/
86 /* Subroutine that describes the purpose of the program */
87 /*----------------------------------------------------------*/
88 Tell:
89 say 'QT will display the current time in natural English.'
90 say 'Call without any arguments to display the time, or with'
91 say '"?" to display this information. A second argument (in'
92 say 'the format "HH:MM:SS") will be used as a test value.'
93 say 'British English idioms are used in this program.'
94 say /* blank line - we are about to continue and show time*/
95 return