1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- G N A T . C A L E N D A R --
11 -- Copyright (C) 1999-2001 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
34 ------------------------------------------------------------------------------
36 -- This package extends Ada.Calendar to handle Hour, Minute, Second,
37 -- Second_Duration and Day_Of_Week and Day_In_Year from Calendar.Time.
38 -- Second_Duration precision depends on the target clock precision.
40 -- GNAT.Calendar provides the same kind of abstraction found in
41 -- Ada.Calendar. It provides Split and Time_Of to build and split a Time
42 -- data. And it provides accessor functions to get only one of Hour, Minute,
43 -- Second, Second_Duration. Other functions are to access more advanced
44 -- valueas like Day_Of_Week, Day_In_Year and Week_In_Year.
49 package GNAT
.Calendar
is
52 (Monday
, Tuesday
, Wednesday
, Thursday
, Friday
, Saturday
, Sunday
);
54 subtype Hour_Number
is Natural range 0 .. 23;
55 subtype Minute_Number
is Natural range 0 .. 59;
56 subtype Second_Number
is Natural range 0 .. 59;
57 subtype Second_Duration
is Ada
.Calendar
.Day_Duration
range 0.0 .. 1.0;
58 subtype Day_In_Year_Number
is Positive range 1 .. 366;
59 subtype Week_In_Year_Number
is Positive range 1 .. 53;
61 function Hour
(Date
: Ada
.Calendar
.Time
) return Hour_Number
;
62 function Minute
(Date
: Ada
.Calendar
.Time
) return Minute_Number
;
63 function Second
(Date
: Ada
.Calendar
.Time
) return Second_Number
;
64 function Sub_Second
(Date
: Ada
.Calendar
.Time
) return Second_Duration
;
65 -- Hour, Minute, Sedond and Sub_Second returns the complete time data for
66 -- the Date (H:M:S.SS). See Ada.Calendar for Year, Month, Day accessors.
67 -- Second_Duration precision depends on the target clock precision.
69 function Day_Of_Week
(Date
: Ada
.Calendar
.Time
) return Day_Name
;
70 -- Return the day name.
72 function Day_In_Year
(Date
: Ada
.Calendar
.Time
) return Day_In_Year_Number
;
73 -- Returns the day number in the year. (1st January is day 1 and 31st
74 -- December is day 365 or 366 for leap year).
76 function Week_In_Year
(Date
: Ada
.Calendar
.Time
) return Week_In_Year_Number
;
77 -- Returns the week number in the year with Monday as first day of week
80 (Date
: Ada
.Calendar
.Time
;
81 Year
: out Ada
.Calendar
.Year_Number
;
82 Month
: out Ada
.Calendar
.Month_Number
;
83 Day
: out Ada
.Calendar
.Day_Number
;
84 Hour
: out Hour_Number
;
85 Minute
: out Minute_Number
;
86 Second
: out Second_Number
;
87 Sub_Second
: out Second_Duration
);
88 -- Split the standard Ada.Calendar.Time data in date data (Year, Month,
89 -- Day) and Time data (Hour, Minute, Second, Sub_Second)
92 (Year
: Ada
.Calendar
.Year_Number
;
93 Month
: Ada
.Calendar
.Month_Number
;
94 Day
: Ada
.Calendar
.Day_Number
;
96 Minute
: Minute_Number
;
97 Second
: Second_Number
;
98 Sub_Second
: Second_Duration
:= 0.0)
99 return Ada
.Calendar
.Time
;
100 -- Returns an Ada.Calendar.Time data built from the date and time values.
102 -- C timeval conversion
104 -- C timeval represent a duration (used in Select for example). This
105 -- structure is composed of a number of seconds and a number of micro
106 -- seconds. The timeval structure is not exposed here because its
107 -- definition is target dependent. Interface to C programs is done via a
108 -- pointer to timeval structure.
110 type timeval
is private;
112 function To_Duration
(T
: access timeval
) return Duration;
113 function To_Timeval
(D
: Duration) return timeval
;
116 -- This is a dummy declaration that should be the largest possible timeval
117 -- structure of all supported targets.
119 type timeval
is array (1 .. 2) of Interfaces
.C
.long
;
122 (Year
: Ada
.Calendar
.Year_Number
;
123 Month
: Ada
.Calendar
.Month_Number
;
124 Day
: Ada
.Calendar
.Day_Number
)
126 -- Compute Julian day number.
128 -- The code of this function is a modified version of algorithm
129 -- 199 from the Collected Algorithms of the ACM.
130 -- The author of algorithm 199 is Robert G. Tantzen.