OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-calend-vms.ads
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-2008, 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 ------------------------------------------------------------------------------
37
38 --  This is the Alpha/VMS version
39
40 with System.OS_Primitives;
41
42 package Ada.Calendar is
43
44    package OSP renames System.OS_Primitives;
45
46    type Time is private;
47
48    --  Declarations representing limits of allowed local time values. Note
49    --  that these do NOT constrain the possible stored values of time which
50    --  may well permit a larger range of times (this is explicitly allowed
51    --  in Ada 95).
52
53    subtype Year_Number  is Integer range 1901 .. 2399;
54    subtype Month_Number is Integer range 1 .. 12;
55    subtype Day_Number   is Integer range 1 .. 31;
56
57    subtype Day_Duration is Duration range 0.0 .. 86_400.0;
58
59    function Clock return Time;
60
61    function Year    (Date : Time) return Year_Number;
62    function Month   (Date : Time) return Month_Number;
63    function Day     (Date : Time) return Day_Number;
64    function Seconds (Date : Time) return Day_Duration;
65
66    procedure Split
67      (Date    : Time;
68       Year    : out Year_Number;
69       Month   : out Month_Number;
70       Day     : out Day_Number;
71       Seconds : out Day_Duration);
72
73    function Time_Of
74      (Year    : Year_Number;
75       Month   : Month_Number;
76       Day     : Day_Number;
77       Seconds : Day_Duration := 0.0) return Time;
78
79    function "+" (Left : Time;     Right : Duration) return Time;
80    function "+" (Left : Duration; Right : Time)     return Time;
81    function "-" (Left : Time;     Right : Duration) return Time;
82    function "-" (Left : Time;     Right : Time)     return Duration;
83
84    function "<"  (Left, Right : Time) return Boolean;
85    function "<=" (Left, Right : Time) return Boolean;
86    function ">"  (Left, Right : Time) return Boolean;
87    function ">=" (Left, Right : Time) return Boolean;
88
89    Time_Error : exception;
90
91 private
92    pragma Inline (Clock);
93
94    pragma Inline (Year);
95    pragma Inline (Month);
96    pragma Inline (Day);
97
98    pragma Inline ("+");
99    pragma Inline ("-");
100
101    pragma Inline ("<");
102    pragma Inline ("<=");
103    pragma Inline (">");
104    pragma Inline (">=");
105
106    --  Although the units are 100 nanoseconds, for the purpose of better
107    --  readability, this unit will be called "mili".
108
109    Mili         : constant := 10_000_000;
110    Mili_F       : constant := 10_000_000.0;
111    Milis_In_Day : constant := 864_000_000_000;
112    Secs_In_Day  : constant := 86_400;
113
114    --  Time is represented as the number of 100-nanosecond (ns) units from the
115    --  system base date and time 1858-11-17 0.0 (the Smithsonian base date and
116    --  time for the astronomic calendar).
117
118    --  The time value stored is typically a UTC 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.
121
122    --  Notwithstanding this definition, Time is not quite the same as OS_Time.
123    --  Relative Time is positive, whereas relative OS_Time is negative,
124    --  but this declaration makes for easier conversion.
125
126    type Time is new OSP.OS_Time;
127
128    Days_In_Month : constant array (Month_Number) of Day_Number :=
129                      (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
130
131    Invalid_Time_Zone_Offset : Long_Integer;
132    pragma Import (C, Invalid_Time_Zone_Offset, "__gnat_invalid_tzoff");
133
134    function Is_Leap (Year : Year_Number) return Boolean;
135    --  Determine whether a given year is leap
136
137    --  The following packages provide a target independent interface to the
138    --  children of Calendar - Arithmetic, Formatting and Time_Zones.
139
140    --  NOTE: Delays does not need a target independent interface because
141    --  VMS already has a target specific file for that package.
142
143    ---------------------------
144    -- Arithmetic_Operations --
145    ---------------------------
146
147    package Arithmetic_Operations is
148
149       function Add (Date : Time; Days : Long_Integer) return Time;
150       --  Add a certain number of days to a time value
151
152       procedure Difference
153         (Left         : Time;
154          Right        : Time;
155          Days         : out Long_Integer;
156          Seconds      : out Duration;
157          Leap_Seconds : out Integer);
158       --  Calculate the difference between two time values in terms of days,
159       --  seconds and leap seconds elapsed. The leap seconds are not included
160       --  in the seconds returned. If Left is greater than Right, the returned
161       --  values are positive, negative otherwise.
162
163       function Subtract (Date : Time; Days : Long_Integer) return Time;
164       --  Subtract a certain number of days from a time value
165
166    end Arithmetic_Operations;
167
168    ---------------------------
169    -- Conversion_Operations --
170    ---------------------------
171
172    package Conversion_Operations is
173       function To_Ada_Time (Unix_Time : Long_Integer) return Time;
174       --  Unix to Ada Epoch conversion
175
176       function To_Ada_Time
177         (tm_year  : Integer;
178          tm_mon   : Integer;
179          tm_day   : Integer;
180          tm_hour  : Integer;
181          tm_min   : Integer;
182          tm_sec   : Integer;
183          tm_isdst : Integer) return Time;
184       --  Struct tm to Ada Epoch conversion
185
186       function To_Duration
187         (tv_sec  : Long_Integer;
188          tv_nsec : Long_Integer) return Duration;
189       --  Struct timespec to Duration conversion
190
191       procedure To_Struct_Timespec
192         (D       : Duration;
193          tv_sec  : out Long_Integer;
194          tv_nsec : out Long_Integer);
195       --  Duration to struct timespec conversion
196
197       procedure To_Struct_Tm
198         (T       : Time;
199          tm_year : out Integer;
200          tm_mon  : out Integer;
201          tm_day  : out Integer;
202          tm_hour : out Integer;
203          tm_min  : out Integer;
204          tm_sec  : out Integer);
205       --  Time to struct tm conversion
206
207       function To_Unix_Time (Ada_Time : Time) return Long_Integer;
208       --  Ada to Unix Epoch conversion
209
210    end Conversion_Operations;
211
212    ---------------------------
213    -- Formatting_Operations --
214    ---------------------------
215
216    package Formatting_Operations is
217
218       function Day_Of_Week (Date : Time) return Integer;
219       --  Determine which day of week Date falls on. The returned values are
220       --  within the range of 0 .. 6 (Monday .. Sunday).
221
222       procedure Split
223         (Date      : Time;
224          Year      : out Year_Number;
225          Month     : out Month_Number;
226          Day       : out Day_Number;
227          Day_Secs  : out Day_Duration;
228          Hour      : out Integer;
229          Minute    : out Integer;
230          Second    : out Integer;
231          Sub_Sec   : out Duration;
232          Leap_Sec  : out Boolean;
233          Is_Ada_05 : Boolean;
234          Time_Zone : Long_Integer);
235       --  Split a time value into its components. Set Is_Ada_05 to use the
236       --  local time zone (the value in Time_Zone is ignored) when splitting
237       --  a time value.
238
239       function Time_Of
240         (Year         : Year_Number;
241          Month        : Month_Number;
242          Day          : Day_Number;
243          Day_Secs     : Day_Duration;
244          Hour         : Integer;
245          Minute       : Integer;
246          Second       : Integer;
247          Sub_Sec      : Duration;
248          Leap_Sec     : Boolean := False;
249          Use_Day_Secs : Boolean := False;
250          Is_Ada_05    : Boolean := False;
251          Time_Zone    : Long_Integer := 0) return Time;
252       --  Given all the components of a date, return the corresponding time
253       --  value. Set Use_Day_Secs to use the value in Day_Secs, otherwise the
254       --  day duration will be calculated from Hour, Minute, Second and Sub_
255       --  Sec. Set Is_Ada_05 to use the local time zone (the value in formal
256       --  Time_Zone is ignored) when building a time value and to verify the
257       --  validity of a requested leap second.
258
259    end Formatting_Operations;
260
261    ---------------------------
262    -- Time_Zones_Operations --
263    ---------------------------
264
265    package Time_Zones_Operations is
266
267       function UTC_Time_Offset (Date : Time) return Long_Integer;
268       --  Return the offset in seconds from UTC
269
270    end Time_Zones_Operations;
271
272 end Ada.Calendar;