OSDN Git Service

2006-10-31 Bob Duff <duff@adacore.com>
[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-2005, 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    function Hour       (Date : Ada.Calendar.Time) return Hour_Number;
60    function Minute     (Date : Ada.Calendar.Time) return Minute_Number;
61    function Second     (Date : Ada.Calendar.Time) return Second_Number;
62    function Sub_Second (Date : Ada.Calendar.Time) return Second_Duration;
63    --  Hour, Minute, Sedond and Sub_Second returns the complete time data for
64    --  the Date (H:M:S.SS). See Ada.Calendar for Year, Month, Day accessors.
65    --  Second_Duration precision depends on the target clock precision.
66
67    function Day_Of_Week (Date : Ada.Calendar.Time) return Day_Name;
68    --  Return the day name
69
70    function Day_In_Year (Date : Ada.Calendar.Time) return Day_In_Year_Number;
71    --  Returns the day number in the year. (1st January is day 1 and 31st
72    --  December is day 365 or 366 for leap year).
73
74    function Week_In_Year (Date : Ada.Calendar.Time) return Week_In_Year_Number;
75    --  Returns the week number in the year with Monday as first day of week
76
77    procedure Split
78      (Date       : Ada.Calendar.Time;
79       Year       : out Ada.Calendar.Year_Number;
80       Month      : out Ada.Calendar.Month_Number;
81       Day        : out Ada.Calendar.Day_Number;
82       Hour       : out Hour_Number;
83       Minute     : out Minute_Number;
84       Second     : out Second_Number;
85       Sub_Second : out Second_Duration);
86    --  Split the standard Ada.Calendar.Time data in date data (Year, Month,
87    --  Day) and Time data (Hour, Minute, Second, Sub_Second)
88
89    function Time_Of
90      (Year       : Ada.Calendar.Year_Number;
91       Month      : Ada.Calendar.Month_Number;
92       Day        : Ada.Calendar.Day_Number;
93       Hour       : Hour_Number;
94       Minute     : Minute_Number;
95       Second     : Second_Number;
96       Sub_Second : Second_Duration := 0.0) return Ada.Calendar.Time;
97    --  Returns an Ada.Calendar.Time data built from the date and time values
98
99    --  C timeval conversion
100
101    --  C timeval represent a duration (used in Select for example). This
102    --  structure is composed of a number of seconds and a number of micro
103    --  seconds. The timeval structure is not exposed here because its
104    --  definition is target dependent. Interface to C programs is done via a
105    --  pointer to timeval structure.
106
107    type timeval is private;
108
109    function To_Duration (T : access timeval) return Duration;
110    function To_Timeval  (D : Duration) return timeval;
111
112 private
113    --  This is a dummy declaration that should be the largest possible timeval
114    --  structure of all supported targets.
115
116    type timeval is array (1 .. 2) of Interfaces.C.long;
117
118    function Julian_Day
119      (Year  : Ada.Calendar.Year_Number;
120       Month : Ada.Calendar.Month_Number;
121       Day   : Ada.Calendar.Day_Number) return Integer;
122    --  Compute Julian day number
123    --
124    --  The code of this function is a modified version of algorithm 199 from
125    --  the Collected Algorithms of the ACM. The author of algorithm 199 is
126    --  Robert G. Tantzen.
127
128 end GNAT.Calendar;