Debian Codegraph @

trip/time.rexx

raw
1 /*
2 * The Regina Rexx Interpreter
3 * Copyright (C) 1992 Anders Christensen <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 written = 0
21
22 /* ======================= DATE ============================== */
23 /* Not a Nice way to do it, but probably the only way ... */
24
25 /* Sun (ofcourse) managed to define their own set of formats, argh! */
26 Week = 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'
27 Mons = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'
28 Months = 'January February March April May June July August',
29 'September October November December'
30
31 parse source os .
32 If os = 'UNIX' | os = 'BEOS' | os = 'QNX' | os = 'SKYOS' Then Signal beforedate
33
34 call notify 'date, time NOT TESTABLE'
35 exit 0
36
37 beforedate:
38 call notify "date"
39 /* call ch date('C'), 'date'("+%j")+trunc(('date'("+%y")-1)*365.25)+365 */
40 call ch date('D'), strip('date'("+%j"),'L','0')
41 call ch date('E'), 'date'("+%d/%m/%y")
42 call ch date('M'), word(Months,'date'("+%m"))
43 call ch date('N'), strip('date'("+%d"),'L','0') word(Mons,'date'("+%m")),
44 "20" || 'date'('+%y')
45 call ch date('O'), 'date'("+%y/%m/%d")
46 call ch date('S'), "20" || 'date'("+%y%m%d")
47 call ch date('U'), 'date'("+%D")
48 call ch date('W'), word(Week,'date'("+%w")+1)
49 call ch date(), date('N')
50 afterdate:
51
52
53
54 /* ======================== TIME ============================== */
55 call notify 'time'
56 /* this will not work at midnight or noon */
57 parse value time(c) time(h) time(l) time(m) time(n) time(s),
58 with timec timeh timel timem timen times
59
60 parse value 'date'('"+%H %M %S"') with hour minute second
61
62 if ( abs((hour*60*60 + minute*60 + second)-times) > 3) then
63 say 'uppps, time is really not that accurate ....'
64
65 /* time(c) */
66
67 if (times > 12*3600) then do
68 times2 = times - 12*3600
69 suff = 'pm'
70 end
71 else do
72 times2 = times
73 suff = 'am'
74 end
75
76 if ((times2%3600)=0) then
77 times2 = 12*3600
78
79 hr = times2%3600
80 if (hr==0) then
81 hr = '12'
82 call ch timec, hr':'right((times%60)//60,2,'0')suff
83
84 /* time(h) */
85 call ch timeh, times%3600
86
87 /* time(m) */
88 call ch timem, times%60
89
90 /* time(n) */
91 call ch timen, right(times%3600,2,"0") || ":" ||,
92 right((times%60)//60,2,"0") || ":" ||,
93 right((times//60),2,"0")
94
95 /* time(l) */
96 parse var timel hour ':' minutes ":" secs '.' after
97 if (after > 499999) then
98 secs = secs + 1
99 if (secs == 60) then do
100 secs = 0
101 minutes = minutes + 1
102 end
103 if (minutes == 60) then do
104 minutes = 0
105 hour = hour + 1
106 end /* ok ... let's just assume it is not midnight .... */
107
108 timel = right(hour,2,'0')':'right(minutes,2,'0')':'right(secs,2,'0')
109 call ch timel, timen
110
111 /* time(s) ... should be ok :-) */
112 call time 'r'
113 'sleep 3'
114 parse value time(e) time(r) time(e) with one two three .
115
116 call ch three, '.000000'
117 call ch one, two
118 call ch one%1, 3
119 aftertime:
120
121
122
123 say ' '
124 exit 0
125
126
127 ch: procedure expose sigl
128 parse arg first, second
129 if first ^== second then do
130 say
131 say 'first = /'first'/'
132 say 'second = /'second'/'
133 say "FuncTrip: error in line" sigl":" sourceline(sigl) ; end
134 return
135
136
137 notify:
138 parse arg word
139 written = written + length(word) + 2
140 if written>75 then do
141 written = length(word)
142 say ' '
143 end
144 call charout , word || ', '
145 return
146
147
148 error:
149 say 'Error discovered in function insert()'
150 return
151