49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
function Four_Digit_Image (Value : Integer) return Atom
is ((1 => Character'Pos ('0') + Octet (Value / 1000),
2 => Character'Pos ('0') + Octet ((Value / 100) mod 10),
3 => Character'Pos ('0') + Octet ((Value / 10) mod 10),
4 => Character'Pos ('0') + Octet (Value mod 10)))
with Pre => Value in 0 .. 9999;
function Parse_Time_Offset
(Image : in String;
Date : in Ada.Calendar.Time)
return Ada.Calendar.Time_Zones.Time_Offset;
procedure Render_Triplet
(Output : in out Ada.Streams.Root_Stream_Type'Class;
Part_1, Part_2, Part_3 : in Atom;
Template : in out Lockable.Descriptor'Class);
procedure Interpreter is new Interpreter_Loop
(Ada.Streams.Root_Stream_Type'Class, Split_Time, Execute, Append);
------------------------------
-- Local Helper Subprograms --
------------------------------
function Parse_Time_Offset
(Image : in String;
Date : in Ada.Calendar.Time)
return Ada.Calendar.Time_Zones.Time_Offset
is
function Value (C : Character)
return Ada.Calendar.Time_Zones.Time_Offset;
function Value (C : Character)
return Ada.Calendar.Time_Zones.Time_Offset is
begin
if C in '0' .. '9' then
return Ada.Calendar.Time_Zones.Time_Offset
(Character'Pos (C) - Character'Pos ('0'));
else
raise Constraint_Error with "Unknown time offset format";
end if;
end Value;
begin
if Image = "system" then
return Ada.Calendar.Time_Zones.UTC_Time_Offset (Date);
end if;
Abbreviation :
begin
return Ada.Calendar.Time_Zones.Time_Offset
(Static_Maps.S_Expressions.Templates.Dates.To_Time_Offset (Image));
exception
when Constraint_Error => null;
end Abbreviation;
Numeric :
declare
use type Ada.Calendar.Time_Zones.Time_Offset;
First : Integer := Image'First;
Length : Natural := Image'Length;
V : Ada.Calendar.Time_Zones.Time_Offset;
Negative : Boolean := False;
begin
if First in Image'Range and then Image (First) in '-' | '+' then
Negative := Image (First) = '-';
First := First + 1;
Length := Length - 1;
end if;
case Length is
when 1 =>
V := Value (Image (First)) * 60;
when 2 =>
V := Value (Image (First)) * 600
+ Value (Image (First + 1)) * 60;
when 4 =>
V := Value (Image (First)) * 600
+ Value (Image (First + 1)) * 60
+ Value (Image (First + 2)) * 10
+ Value (Image (First + 3));
when 5 =>
if Image (First + 2) in '0' .. '9' then
raise Constraint_Error with "Unknown time offset format";
end if;
V := Value (Image (First)) * 600
+ Value (Image (First + 1)) * 60
+ Value (Image (First + 3)) * 10
+ Value (Image (First + 4));
when others =>
raise Constraint_Error with "Unknown time offset format";
end case;
if Negative then
return -V;
else
return V;
end if;
end Numeric;
end Parse_Time_Offset;
procedure Render_Triplet
(Output : in out Ada.Streams.Root_Stream_Type'Class;
Part_1, Part_2, Part_3 : in Atom;
Template : in out Lockable.Descriptor'Class) is
begin
Output.Write (Part_1);
|
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
|
when Commands.RFC_3339 =>
Output.Write (To_Atom
(Time_IO.RFC_3339.Image (Value.Source, Value.Time_Zone)));
when Commands.Second =>
Format.Set_Image (-1, Null_Atom);
Integers.Render (Output, Format, Arguments, Value.Second);
when Commands.With_Offset =>
if Arguments.Current_Event = Events.Add_Atom then
declare
use type Ada.Calendar.Time_Zones.Time_Offset;
New_Offset : Ada.Calendar.Time_Zones.Time_Offset;
begin
begin
New_Offset := Parse_Time_Offset
(S_Expressions.To_String (Arguments.Current_Atom),
Value.Source);
exception
when Constraint_Error => return;
end;
Arguments.Next;
if New_Offset = Value.Time_Zone then
Interpreter (Arguments, Output, Value);
else
Render (Output, Arguments, Value.Source, New_Offset);
end if;
end;
end if;
when Commands.Year =>
Integers.Render (Output, Arguments, Value.Year);
end case;
end Execute;
procedure Interpreter is new Interpreter_Loop
(Ada.Streams.Root_Stream_Type'Class, Split_Time, Execute, Append);
----------------------
-- Public Interface --
----------------------
function Split
|