35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
-- Local Helper Subprograms --
------------------------------
function Explicit_Sign (Image : String) return String
is (if Image'Length > 0 and then Image (Image'First) = ' '
then '+' & Image (Image'First + 1 .. Image'Last)
else Image);
function Image (Time : Extended_Time) return String
is ('[' & Ada.Calendar.Formatting.Image (Time.Time) & "] "
& Explicit_Sign
(Ada.Calendar.Time_Zones.Time_Offset'Image (Time.Offset)));
function Quote (Original : String) return String
is ('"' & Original & '"');
procedure Check is new NT.Generic_Check (Extended_Time);
procedure Check is new NT.Generic_Check (String, "=", Quote);
-------------------------
-- Complete Test Suite --
-------------------------
procedure All_Tests (Report : in out NT.Reporter'Class) is
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
|
-- Local Helper Subprograms --
------------------------------
function Explicit_Sign (Image : String) return String
is (if Image'Length > 0 and then Image (Image'First) = ' '
then '+' & Image (Image'First + 1 .. Image'Last)
else Image);
function Has_Leap_Second_Support return Boolean;
function Image (Time : Extended_Time) return String
is ('[' & Ada.Calendar.Formatting.Image (Time.Time) & "] "
& Explicit_Sign
(Ada.Calendar.Time_Zones.Time_Offset'Image (Time.Offset)));
function Quote (Original : String) return String
is ('"' & Original & '"');
procedure Check is new NT.Generic_Check (Extended_Time);
procedure Check is new NT.Generic_Check (String, "=", Quote);
function Has_Leap_Second_Support return Boolean is
Leap_Second_Time : Ada.Calendar.Time;
Year : Ada.Calendar.Year_Number;
Month : Ada.Calendar.Month_Number;
Day : Ada.Calendar.Day_Number;
Hour : Ada.Calendar.Formatting.Hour_Number;
Minute : Ada.Calendar.Formatting.Minute_Number;
Second : Ada.Calendar.Formatting.Second_Number;
Sub_Second : Ada.Calendar.Formatting.Second_Duration;
Is_Leap_Second : Boolean;
begin
begin
Leap_Second_Time := Ada.Calendar.Formatting.Time_Of
(1990, 12, 31, 23, 59, 59, 0.25, True, 0);
exception
when Ada.Calendar.Time_Error =>
-- Leap second are explicitly not supported
return False;
end;
Ada.Calendar.Formatting.Split
(Leap_Second_Time,
Year, Month, Day,
Hour, Minute, Second, Sub_Second,
Is_Leap_Second,
Time_Zone => 0);
-- Check that Time_Of/Split at least work on the normal part
pragma Assert (Year = 1990);
pragma Assert (Month = 12);
pragma Assert (Day = 31);
pragma Assert (Hour = 23);
pragma Assert (Minute = 59);
pragma Assert (Second = 59);
pragma Assert (Sub_Second = 0.25);
-- According to the standard, Is_Leap_Second should be True at this
-- point, because Time_Error should have been raised if leap second is
-- not supported.
-- However some implementations mistakenly drop silently Leap_Second,
-- so actual support is determined here by check Is_Leap_Second.
return Is_Leap_Second;
end Has_Leap_Second_Support;
-------------------------
-- Complete Test Suite --
-------------------------
procedure All_Tests (Report : in out NT.Reporter'Class) is
|
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
Check (Test,
(Ada.Calendar.Formatting.Time_Of
(1996, 12, 19, 16, 39, 57, 0.0, False, -8 * 60), -8 * 60),
Value ("1996-12-19T16:39:57-08:00"),
"[2] Time with negative offset:");
Check (Test,
(Ada.Calendar.Formatting.Time_Of
(1990, 12, 31, 23, 59, 59, 0.0, True, 0), 0),
Value ("1990-12-31T23:59:60Z"),
"[3] UTC leap second:");
Check (Test,
(Ada.Calendar.Formatting.Time_Of
(1990, 12, 31, 15, 59, 59, 0.0, True, -8 * 60), -8 * 60),
Value ("1990-12-31T15:59:60-08:00"),
"[4] Leap second with time offset:");
Check (Test,
(Ada.Calendar.Formatting.Time_Of
(1937, 01, 01, 12, 0, 27, 0.87, False, 20), 20),
Value ("1937-01-01T12:00:27.87+00:20"),
"[5] Noon in the Netherlands:");
|
>
|
|
|
|
|
|
|
|
|
|
>
|
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
Check (Test,
(Ada.Calendar.Formatting.Time_Of
(1996, 12, 19, 16, 39, 57, 0.0, False, -8 * 60), -8 * 60),
Value ("1996-12-19T16:39:57-08:00"),
"[2] Time with negative offset:");
if Has_Leap_Second_Support then
Check (Test,
(Ada.Calendar.Formatting.Time_Of
(1990, 12, 31, 23, 59, 59, 0.0, True, 0), 0),
Value ("1990-12-31T23:59:60Z"),
"[3] UTC leap second:");
Check (Test,
(Ada.Calendar.Formatting.Time_Of
(1990, 12, 31, 15, 59, 59, 0.0, True, -8 * 60), -8 * 60),
Value ("1990-12-31T15:59:60-08:00"),
"[4] Leap second with time offset:");
end if;
Check (Test,
(Ada.Calendar.Formatting.Time_Of
(1937, 01, 01, 12, 0, 27, 0.87, False, 20), 20),
Value ("1937-01-01T12:00:27.87+00:20"),
"[5] Noon in the Netherlands:");
|
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
"1996-12-19T16:39:57-08:00",
RFC_3339.Image
(Ada.Calendar.Formatting.Time_Of
(1996, 12, 19, 16, 39, 57, 0.0, False, -8 * 60),
-8 * 60, 0),
"[2] Time with negative offset:");
Check (Test,
"1990-12-31T23:59:60Z",
RFC_3339.Image
(Ada.Calendar.Formatting.Time_Of
(1990, 12, 31, 23, 59, 59, 0.0, True, 0),
0, 0),
"[3] UTC leap second:");
Check (Test,
"1990-12-31T15:59:60-08:00",
RFC_3339.Image
(Ada.Calendar.Formatting.Time_Of
(1990, 12, 31, 15, 59, 59, 0.0, True, -8 * 60),
-8 * 60, 0),
"[4] Leap second with time offset:");
Check (Test,
"1937-01-01T12:00:27.87+00:20",
RFC_3339.Image
(Ada.Calendar.Formatting.Time_Of
(1937, 01, 01, 12, 0, 27, 0.87, False, 20),
20, 2),
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
"1996-12-19T16:39:57-08:00",
RFC_3339.Image
(Ada.Calendar.Formatting.Time_Of
(1996, 12, 19, 16, 39, 57, 0.0, False, -8 * 60),
-8 * 60, 0),
"[2] Time with negative offset:");
if Has_Leap_Second_Support then
Check (Test,
"1990-12-31T23:59:60Z",
RFC_3339.Image
(Ada.Calendar.Formatting.Time_Of
(1990, 12, 31, 23, 59, 59, 0.0, True, 0),
0, 0),
"[3] UTC leap second:");
Check (Test,
"1990-12-31T15:59:60-08:00",
RFC_3339.Image
(Ada.Calendar.Formatting.Time_Of
(1990, 12, 31, 15, 59, 59, 0.0, True, -8 * 60),
-8 * 60, 0),
"[4] Leap second with time offset:");
end if;
Check (Test,
"1937-01-01T12:00:27.87+00:20",
RFC_3339.Image
(Ada.Calendar.Formatting.Time_Of
(1937, 01, 01, 12, 0, 27, 0.87, False, 20),
20, 2),
|