OSDN Git Service

gcc/ada/
[pf3gnuchains/gcc-fork.git] / gcc / ada / g-calend.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUN-TIME COMPONENTS                         --
4 --                                                                          --
5 --                         G N A T . C A L E N D A R                        --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1999-2007, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  This package extends Ada.Calendar to handle Hour, Minute, Second,
35 --  Second_Duration and Day_Of_Week and Day_In_Year from Calendar.Time.
36 --  Second_Duration precision depends on the target clock precision.
37 --
38 --  GNAT.Calendar provides the same kind of abstraction found in
39 --  Ada.Calendar. It provides Split and Time_Of to build and split a Time
40 --  data. And it provides accessor functions to get only one of Hour, Minute,
41 --  Second, Second_Duration. Other functions are to access more advanced
42 --  valueas like Day_Of_Week, Day_In_Year and Week_In_Year.
43
44 with Ada.Calendar;
45 with Interfaces.C;
46
47 package GNAT.Calendar is
48
49    type Day_Name is
50      (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
51
52    subtype Hour_Number         is Natural range 0 .. 23;
53    subtype Minute_Number       is Natural range 0 .. 59;
54    subtype Second_Number       is Natural range 0 .. 59;
55    subtype Second_Duration     is Ada.Calendar.Day_Duration range 0.0 .. 1.0;
56    subtype Day_In_Year_Number  is Positive range 1 .. 366;
57    subtype Week_In_Year_Number is Positive range 1 .. 53;
58
59    No_Time : constant Ada.Calendar.Time;
60    --  A constant set to the first date that can be represented by the type
61    --  Time. It can be used to indicate an uninitialized date.
62
63    function Hour       (Date : Ada.Calendar.Time) return Hour_Number;
64    function Minute     (Date : Ada.Calendar.Time) return Minute_Number;
65    function Second     (Date : Ada.Calendar.Time) return Second_Number;
66    function Sub_Second (Date : Ada.Calendar.Time) return Second_Duration;
67    --  Hour, Minute, Sedond and Sub_Second returns the complete time data for
68    --  the Date (H:M:S.SS). See Ada.Calendar for Year, Month, Day accessors.
69    --  Second_Duration precision depends on the target clock precision.
70
71    function Day_Of_Week (Date : Ada.Calendar.Time) return Day_Name;
72    --  Return the day name
73
74    function Day_In_Year (Date : Ada.Calendar.Time) return Day_In_Year_Number;
75    --  Returns the day number in the year. (1st January is day 1 and 31st
76    --  December is day 365 or 366 for leap year).
77
78    function Week_In_Year (Date : Ada.Calendar.Time) return Week_In_Year_Number;
79    --  Returns the week number as defined in ISO 8601. A week always starts on
80    --  a Monday and the first week of a particular year is the one containing
81    --  the first Thursday. A year may have 53 weeks when January 1st is a
82    --  Wednesday and the year is leap or January 1st is a Thursday. Note that
83    --  the last days of December may belong to the first week on the next year
84    --  and conversely, the first days of January may belong to the last week
85    --  of the last year.
86
87    procedure Split
88      (Date       : Ada.Calendar.Time;
89       Year       : out Ada.Calendar.Year_Number;
90       Month      : out Ada.Calendar.Month_Number;
91       Day        : out Ada.Calendar.Day_Number;
92       Hour       : out Hour_Number;
93       Minute     : out Minute_Number;
94       Second     : out Second_Number;
95       Sub_Second : out Second_Duration);
96    --  Split the standard Ada.Calendar.Time data in date data (Year, Month,
97    --  Day) and Time data (Hour, Minute, Second, Sub_Second)
98
99    function Time_Of
100      (Year       : Ada.Calendar.Year_Number;
101       Month      : Ada.Calendar.Month_Number;
102       Day        : Ada.Calendar.Day_Number;
103       Hour       : Hour_Number;
104       Minute     : Minute_Number;
105       Second     : Second_Number;
106       Sub_Second : Second_Duration := 0.0) return Ada.Calendar.Time;
107    --  Returns an Ada.Calendar.Time data built from the date and time values
108
109    --  C timeval conversion
110
111    --  C timeval represent a duration (used in Select for example). This
112    --  structure is composed of a number of seconds and a number of micro
113    --  seconds. The timeval structure is not exposed here because its
114    --  definition is target dependent. Interface to C programs is done via a
115    --  pointer to timeval structure.
116
117    type timeval is private;
118
119    function To_Duration (T : not null access timeval) return Duration;
120    function To_Timeval  (D : Duration) return timeval;
121
122 private
123    --  This is a dummy declaration that should be the largest possible timeval
124    --  structure of all supported targets.
125
126    type timeval is array (1 .. 2) of Interfaces.C.long;
127
128    function Julian_Day
129      (Year  : Ada.Calendar.Year_Number;
130       Month : Ada.Calendar.Month_Number;
131       Day   : Ada.Calendar.Day_Number) return Integer;
132    --  Compute Julian day number
133    --
134    --  The code of this function is a modified version of algorithm 199 from
135    --  the Collected Algorithms of the ACM. The author of algorithm 199 is
136    --  Robert G. Tantzen.
137
138    No_Time : constant Ada.Calendar.Time :=
139                Ada.Calendar.Time_Of
140                  (Ada.Calendar.Year_Number'First,
141                   Ada.Calendar.Month_Number'First,
142                   Ada.Calendar.Day_Number'First);
143
144 end GNAT.Calendar;