2005-05-11 Kenneth Zadeck <zadeck@naturalbridge.com>
[official-gcc.git] / gcc / ada / g-calend.ads
blob94f95a18e21057872f2ffd4af38f111287f0984e
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-2001 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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 ------------------------------------------------------------------------------
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.
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.
44 with Ada.Calendar;
45 with Interfaces.C;
47 package GNAT.Calendar is
49 type Day_Name is
50 (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
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;
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.
67 function Day_Of_Week (Date : Ada.Calendar.Time) return Day_Name;
68 -- Return the day name.
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).
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
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)
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)
97 return Ada.Calendar.Time;
98 -- Returns an Ada.Calendar.Time data built from the date and time values.
100 -- C timeval conversion
102 -- C timeval represent a duration (used in Select for example). This
103 -- structure is composed of a number of seconds and a number of micro
104 -- seconds. The timeval structure is not exposed here because its
105 -- definition is target dependent. Interface to C programs is done via a
106 -- pointer to timeval structure.
108 type timeval is private;
110 function To_Duration (T : access timeval) return Duration;
111 function To_Timeval (D : Duration) return timeval;
113 private
114 -- This is a dummy declaration that should be the largest possible timeval
115 -- structure of all supported targets.
117 type timeval is array (1 .. 2) of Interfaces.C.long;
119 function Julian_Day
120 (Year : Ada.Calendar.Year_Number;
121 Month : Ada.Calendar.Month_Number;
122 Day : Ada.Calendar.Day_Number)
123 return Integer;
124 -- Compute Julian day number.
126 -- The code of this function is a modified version of algorithm
127 -- 199 from the Collected Algorithms of the ACM.
128 -- The author of algorithm 199 is Robert G. Tantzen.
129 end GNAT.Calendar;