|
» |
|
|
|
The user is asked to enter a language.
All date and time formatting and conversion
is done by using the language entered by the user.
The time and date used in the examples is the current
system time obtained by calling the HP 3000 system
intrinsics CALENDAR and CLOCK.
1 $CONTROL USLINIT
2 BEGIN
3 LOGICAL ARRAY
4 L'ERROR (0:1),
5 L'LANGUAGE (0:7),
6 L'PRINT (0:39),
7 L'CUSTOM'DATE (0:6),
8 L'DATE (0:13),
9 L'CALENDAR (0:8),
10 L'MONTHS (0:71),
11 L'WEEKDAYS (0:41),
12 L'CLOCK (0:3);
13
14 BYTE ARRAY
15 B'PRINT(*) = L'PRINT,
16 B'CUSTOM'DATE(*) = L'CUSTOM'DATE,
17 B'CALENDAR(*) = L'CALENDAR,
18 B'DATE(*) = L'DATE,
19 B'MONTHS(*) = L'MONTHS,
20 B'WEEKDAYS(*) = L'WEEKDAYS,
21 B'CLOCK(*) = L'CLOCK;
22
23 BYTE POINTER
24 BP'PRINT;
25
26 DOUBLE
27 TIME;
28
29 LOGICAL
30 DATE,
31 HOUR'MINUTE = TIME,
32 SECONDS = TIME + 1;
33
34 INTEGER
35 YEAR,
36 MONTH,
37 DAY,
38 WEEKDAY,
39 LGTH,
40 LANGNUM;
41
42 DEFINE
43 WEEKDAY'NAME = B'WEEKDAYS((WEEKDAY - 1) * 12)#,
44
45 MONTH'NAME = B'MONTHS((MONTH - 1) * 12)#,
46
47 ERR'CHECK = IF L'ERROR(0) <> 0 THEN
48 QUIT #,
49
50 CCNE = IF <> THEN
51 QUIT #,
52
53 DISPLAY = MOVE B'PRINT := #,
54
55 ON'STDLIST = ,2;
56 @BP'PRINT := TOS;
57 LGTH := LOGICAL(@BP'PRINT) -
58 LOGICAL(@B'PRINT);
59 PRINT(L'PRINT, -LGTH, 0) #;
60
61 INTRINSIC
62 READ,
63 QUIT,
64 PRINT,
65 CLOCK,
66 CALENDAR,
67 ALMANAC,
68 NLINFO,
69 NLFMTCLOCK,
70 NLCONVCLOCK,
71 NLFMTDATE,
72 NLFMTCALENDAR,
73 NLFMTCUSTDATE,
74 NLCONVCUSTDATE;
75
76
77 << Start of main code.
78 The user is asked to enter a language name or number.>>
79
80 DISPLAY
81 "ENTER A LANGUAGE NAME OR NUMBER (MAX. 16 CHARACTERS):"
82 ON'STDLIST;
83
84 READ(L'LANGUAGE,-16);
85
86 << NLINFO item 22 returns the corresponding
87 lang number in integer format for this language. >>
88
89 NLINFO(22,L'LANGUAGE,LANGNUM,L'ERROR);
90 IF L'ERROR(0) <> 0 THEN
91 BEGIN
92 IF L'ERROR(0) = 1 THEN
93 BEGIN
94 DISPLAY
95 "NL/3000 IS NOT INSTALLED"
96 ON'STDLIST;
97 QUIT(1001);
98 END
99 ELSE
100 IF L'ERROR(0) = 2 THEN
101 BEGIN
102 DISPLAY
103 "THIS LANGUAGE IS NOT CONFIGURED"
104 ON'STDLIST;
105 QUIT(1002);
106 END
107 ELSE
108 QUIT (1000 + L'ERROR(0));
109 END;
110
111 << This obtains the machine internal clock and
112 calendar formats which is maintained by MPE.>>
113
114 TIME := CLOCK;
115
116 DATE := CALENDAR;
117
118 << Call ALMANAC and convert the machine internal date
119 format into numeric values, which will be used as indices
120 into the name tables.>>
121
122 ALMANAC(DATE, L'ERROR, , MONTH, , WEEKDAY);
123 ERR'CHECK (2000 + L'ERROR(0));
124
125 << Call the tables for month and weekday names and
126 display todays day name and the current month's name.>>
127
128 NLINFO(5, L'MONTHS, LANGNUM, L'ERROR);
129 ERR'CHECK (3000 + L'ERROR(0));
130
131 DISPLAY MONTH'NAME,(12) ON'STDLIST;
132
133 NLINFO(7, L'WEEKDAYS, LANGNUM, L'ERROR);
134 ERR'CHECK (4000 + L'ERROR(0));
135
136 DISPLAY WEEKDAY'NAME,(12) ON'STDLIST;
137
138 << Format the machine internal date format
139 into the custom date format (short version).
140 The result will be displayed.>>
141
142 NLFMTCUSTDATE(DATE,L'CUSTOM'DATE,LANGNUM,L'ERROR);
143 ERR'CHECK (5000 + L'ERROR(0));
144
145 DISPLAY "CUSTOM DATE:" ON'STDLIST;
146 DISPLAY B'CUSTOM'DATE,(13) ON'STDLIST;
147
148 << Use the output of NLFMTCUSTDATE as input for
149 NLCONVCUSTDATE and convert back to the internal format.>>
150
151 DATE := NLCONVCUSTDATE(B'CUSTOM'DATE,13,LANGNUM,L'ERROR);
152 ERR'CHECK (6000 + L'ERROR(0));
153
154 << Format the machine internal date format into the
155 date format (long format) according to the language.
156 The result will be displayed.>>
157
158 NLFMTCALENDAR(DATE,L'CALENDAR,LANGNUM,L'ERROR);
159 ERR'CHECK (7000 + L'ERROR(0));
160
161 DISPLAY "DATE FORMAT:" ON'STDLIST;
162 DISPLAY B'CALENDAR,(18) ON'STDLIST;
163
164 << Format the machine internal clock format
165 into the language-dependent clock format.
166 The result will be displayed.>>
167
168 NLFMTCLOCK(TIME,L'CLOCK,LANGNUM,L'ERROR);
169 ERR'CHECK (8000 + L'ERROR(0));
170
171 DISPLAY "TIME FORMAT:" ON'STDLIST;
172 DISPLAY B'CLOCK,(8) ON'STDLIST;
173
174 << Use the output of NLFMTCLOCK as input for
175 NLCONVCLOCK and convert back to the internal format.>>
176
177 TIME := NLCONVCLOCK(B'CLOCK,8,LANGNUM,L'ERROR);
178 ERR'CHECK (9000 + L'ERROR(0));
179
180 << Format the machine internal time and date
181 format into the language-dependent format.
182 The result will be displayed.>>
183
184 NLFMTDATE(DATE,TIME,L'DATE,LANGNUM,L'ERROR);
185 ERR'CHECK (10000 + L'ERROR(0));
186
187 DISPLAY "DATE AND TIME FORMAT:" ON'STDLIST;
188 DISPLAY B'DATE,(28) ON'STDLIST;
189
190 END.
|
Executing the program results in the following:
:RUN PROGRAM
ENTER A LANGUAGE NAME OR NUMBER (MAX. 16 CHARACTERS):
GERMAN
January
Dienstag
CUSTOM DATE:
31.01.84
DATE FORMAT:
Di., 31. Jan. 1984
TIME FORMAT:
17:12
DATE AND TIME FORMAT:
Di., 31. Jan. 1984, 17:12
END OF PROGRAM
|
:RUN PROGRAM
ENTER A LANGUAGE NAME OR NUMBER (MAX. 16 CHARACTERS):
0
JANUARY
TUESDAY
CUSTOM DATE:
01/31/84
DATE FORMAT:
TUE, JAN 31, 1984
TIME FORMAT:
5:13 PM
DATE AND TIME FORMAT:
TUE, JAN 31, 1984, 5:13 PM
END OF PROGRAM
:
|
|