111
|
1 ------------------------------------------------------------------------------
|
|
2 -- --
|
|
3 -- GNAT RUN-TIME COMPONENTS --
|
|
4 -- --
|
|
5 -- A D A . C A L E N D A R . A R I T H M E T I C --
|
|
6 -- --
|
|
7 -- S p e c --
|
|
8 -- --
|
|
9 -- Copyright (C) 2005-2017, Free Software Foundation, Inc. --
|
|
10 -- --
|
|
11 -- This specification is derived from the Ada Reference Manual for use with --
|
|
12 -- GNAT. In accordance with the copyright of that document, you can freely --
|
|
13 -- copy and modify this specification, provided that if you redistribute a --
|
|
14 -- modified version, any changes that you have made are clearly indicated. --
|
|
15 -- --
|
|
16 ------------------------------------------------------------------------------
|
|
17
|
|
18 -- This package provides arithmetic operations of time values using days
|
|
19 -- and leap seconds. Ada.Calendar.Arithmetic is defined in the Ada 2005
|
|
20 -- RM (9.6.1).
|
|
21
|
|
22 package Ada.Calendar.Arithmetic is
|
|
23
|
|
24 -- Arithmetic on days:
|
|
25
|
|
26 -- Rough estimate on the number of days over the range of Ada time
|
|
27
|
|
28 type Day_Count is range
|
|
29 -(366 * (1 + Year_Number'Last - Year_Number'First))
|
|
30 ..
|
|
31 +(366 * (1 + Year_Number'Last - Year_Number'First));
|
|
32
|
|
33 subtype Leap_Seconds_Count is Integer range -2047 .. 2047;
|
|
34 -- Count of leap seconds. Negative leap seconds occur whenever the
|
|
35 -- astronomical time is faster than the atomic time or as a result of
|
|
36 -- Difference when Left < Right.
|
|
37
|
|
38 procedure Difference
|
|
39 (Left : Time;
|
|
40 Right : Time;
|
|
41 Days : out Day_Count;
|
|
42 Seconds : out Duration;
|
|
43 Leap_Seconds : out Leap_Seconds_Count);
|
|
44 -- Returns the difference between Left and Right. Days is the number of
|
|
45 -- days of difference, Seconds is the remainder seconds of difference
|
|
46 -- excluding leap seconds, and Leap_Seconds is the number of leap seconds.
|
|
47 -- If Left < Right, then Seconds <= 0.0, Days <= 0, and Leap_Seconds <= 0,
|
|
48 -- otherwise all values are nonnegative. The absolute value of Seconds is
|
|
49 -- always less than 86_400.0. For the returned values, if Days = 0, then
|
|
50 -- Seconds + Duration (Leap_Seconds) = Calendar."-" (Left, Right)
|
|
51
|
|
52 function "+" (Left : Time; Right : Day_Count) return Time;
|
|
53 function "+" (Left : Day_Count; Right : Time) return Time;
|
|
54 -- Adds a number of days to a time value. Time_Error is raised if the
|
|
55 -- result is not representable as a value of type Time.
|
|
56
|
|
57 function "-" (Left : Time; Right : Day_Count) return Time;
|
|
58 -- Subtracts a number of days from a time value. Time_Error is raised if
|
|
59 -- the result is not representable as a value of type Time.
|
|
60
|
|
61 function "-" (Left : Time; Right : Time) return Day_Count;
|
|
62 -- Subtracts two time values, and returns the number of days between them.
|
|
63 -- This is the same value that Difference would return in Days.
|
|
64
|
|
65 end Ada.Calendar.Arithmetic;
|