gcc:
[official-gcc.git] / gcc / ada / a-calend.ads
blob9f4e66a1d43c8c02aed9d82b1a846262d3eb3397
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . C A L E N D A R --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
10 -- --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
14 -- --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 2, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
21 -- for more details. You should have received a copy of the GNU General --
22 -- Public License distributed with GNAT; see file COPYING. If not, write --
23 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
24 -- Boston, MA 02110-1301, USA. --
25 -- --
26 -- As a special exception, if other files instantiate generics from this --
27 -- unit, or you link this unit with other files to produce an executable, --
28 -- this unit does not by itself cause the resulting executable to be --
29 -- covered by the GNU General Public License. This exception does not --
30 -- however invalidate any other reasons why the executable file might be --
31 -- covered by the GNU Public License. --
32 -- --
33 -- GNAT was originally developed by the GNAT team at New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc. --
35 -- --
36 ------------------------------------------------------------------------------
38 package Ada.Calendar is
40 type Time is private;
42 -- Declarations representing limits of allowed local time values. Note that
43 -- these do NOT constrain the possible stored values of time which may well
44 -- permit a larger range of times (this is explicitly allowed in Ada 95).
46 subtype Year_Number is Integer range 1901 .. 2099;
47 subtype Month_Number is Integer range 1 .. 12;
48 subtype Day_Number is Integer range 1 .. 31;
50 subtype Day_Duration is Duration range 0.0 .. 86_400.0;
52 function Clock return Time;
54 function Year (Date : Time) return Year_Number;
55 function Month (Date : Time) return Month_Number;
56 function Day (Date : Time) return Day_Number;
57 function Seconds (Date : Time) return Day_Duration;
59 procedure Split
60 (Date : Time;
61 Year : out Year_Number;
62 Month : out Month_Number;
63 Day : out Day_Number;
64 Seconds : out Day_Duration);
66 function Time_Of
67 (Year : Year_Number;
68 Month : Month_Number;
69 Day : Day_Number;
70 Seconds : Day_Duration := 0.0) return Time;
71 -- GNAT Note: Normally when procedure Split is called on a Time value
72 -- result of a call to function Time_Of, the out parameters of procedure
73 -- Split are identical to the in parameters of function Time_Of. However,
74 -- when a non-existent time of day is specified, the values for Seconds
75 -- may or may not be different. This may happen when Daylight Saving Time
76 -- (DST) is in effect, on the day when switching to DST, if Seconds
77 -- specifies a time of day in the hour that does not exist. For example,
78 -- in New York:
80 -- Time_Of (Year => 1998, Month => 4, Day => 5, Seconds => 10740.0)
82 -- will return a Time value T. If Split is called on T, the resulting
83 -- Seconds may be 14340.0 (3:59:00) instead of 10740.0 (2:59:00 being
84 -- a time that not exist).
86 function "+" (Left : Time; Right : Duration) return Time;
87 function "+" (Left : Duration; Right : Time) return Time;
88 function "-" (Left : Time; Right : Duration) return Time;
89 function "-" (Left : Time; Right : Time) return Duration;
91 function "<" (Left, Right : Time) return Boolean;
92 function "<=" (Left, Right : Time) return Boolean;
93 function ">" (Left, Right : Time) return Boolean;
94 function ">=" (Left, Right : Time) return Boolean;
96 Time_Error : exception;
98 private
99 pragma Inline (Clock);
101 pragma Inline (Year);
102 pragma Inline (Month);
103 pragma Inline (Day);
105 pragma Inline ("+");
106 pragma Inline ("-");
108 pragma Inline ("<");
109 pragma Inline ("<=");
110 pragma Inline (">");
111 pragma Inline (">=");
113 -- Time is represented as a signed duration from the base point which is
114 -- what Unix calls the EPOCH (i.e. 12 midnight (24:00:00), Dec 31st, 1969,
115 -- or if you prefer 0:00:00 on Jan 1st, 1970). Since Ada allows dates
116 -- before this EPOCH value, the stored duration value may be negative.
118 -- The time value stored is typically a GMT value, as provided in standard
119 -- Unix environments. If this is the case then Split and Time_Of perform
120 -- required conversions to and from local times. The range of times that
121 -- can be stored in Time values depends on the declaration of the type
122 -- Duration, which must at least cover the required Ada range represented
123 -- by the declaration of Year_Number, but may be larger (we take full
124 -- advantage of the new permission in Ada 95 to store time values outside
125 -- the range that would be acceptable to Split). The Duration type is a
126 -- real value representing a time interval in seconds.
128 type Time is new Duration;
130 -- The following package provides handling of leap seconds. It is
131 -- used by Ada.Calendar.Arithmetic and Ada.Calendar.Formatting, both
132 -- Ada 2005 children of Ada.Calendar.
134 package Leap_Sec_Ops is
136 After_Last_Leap : constant Time := Time'Last;
137 -- Bigger by far than any leap second value. Not within range of
138 -- Ada.Calendar specified dates.
140 procedure Cumulative_Leap_Secs
141 (Start_Date : Time;
142 End_Date : Time;
143 Leaps_Between : out Duration;
144 Next_Leap_Sec : out Time);
145 -- Leaps_Between is the sum of the leap seconds that have occured
146 -- on or after Start_Date and before (strictly before) End_Date.
147 -- Next_Leap_Sec represents the next leap second occurence on or
148 -- after End_Date. If there are no leaps seconds after End_Date,
149 -- After_Last_Leap is returned. This does not provide info about
150 -- the next leap second (pos/neg or ?). After_Last_Leap can be used
151 -- as End_Date to count all the leap seconds that have occured on
152 -- or after Start_Date.
154 -- Important Notes: any fractional parts of Start_Date and End_Date
155 -- are discarded before the calculations are done. For instance: if
156 -- 113 seconds is a leap second (it isn't) and 113.5 is input as an
157 -- End_Date, the leap second at 113 will not be counted in
158 -- Leaps_Between, but it will be returned as Next_Leap_Sec. Thus, if
159 -- the caller wants to know if the End_Date is a leap second, the
160 -- comparison should be:
162 -- End_Date >= Next_Leap_Sec;
164 -- After_Last_Leap is designed so that this comparison works without
165 -- having to first check if Next_Leap_Sec is a valid leap second.
167 function All_Leap_Seconds return Duration;
168 -- Returns the sum off all of the leap seoncds.
170 end Leap_Sec_Ops;
172 procedure Split_With_Offset
173 (Date : Time;
174 Year : out Year_Number;
175 Month : out Month_Number;
176 Day : out Day_Number;
177 Seconds : out Day_Duration;
178 Offset : out Long_Integer);
179 -- Split_W_Offset has the same spec as Split with the addition of an
180 -- offset value which give the offset of the local time zone from UTC
181 -- at the input Date. This value comes for free during the implementation
182 -- of Split and is needed by UTC_Time_Offset. The returned Offset time
183 -- is straight from the C tm struct and is in seconds. If the system
184 -- dependent code has no way to find the offset it will return the value
185 -- Invalid_TZ_Offset declared below. Otherwise no checking is done, so
186 -- it is up to the user to check both for Invalid_TZ_Offset and otherwise
187 -- for a value that is acceptable.
189 Invalid_TZ_Offset : Long_Integer;
190 pragma Import (C, Invalid_TZ_Offset, "__gnat_invalid_tzoff");
192 end Ada.Calendar;