annotate gcc/ada/libgnat/g-calend.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- G N A T . C A L E N D A R --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1999-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This package extends Ada.Calendar to handle Hour, Minute, Second,
kono
parents:
diff changeset
33 -- Second_Duration and Day_Of_Week and Day_In_Year from Calendar.Time.
kono
parents:
diff changeset
34 -- Second_Duration precision depends on the target clock precision.
kono
parents:
diff changeset
35 --
kono
parents:
diff changeset
36 -- GNAT.Calendar provides the same kind of abstraction found in Ada.Calendar.
kono
parents:
diff changeset
37 -- It provides Split and Time_Of to build and split a Time data. And it
kono
parents:
diff changeset
38 -- provides accessor functions to get only one of Hour, Minute, Second,
kono
parents:
diff changeset
39 -- Second_Duration. Other functions are to access more advanced values like
kono
parents:
diff changeset
40 -- Day_Of_Week, Day_In_Year and Week_In_Year.
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 with Ada.Calendar.Formatting;
kono
parents:
diff changeset
43 with Interfaces.C;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 package GNAT.Calendar is
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 type Day_Name is
kono
parents:
diff changeset
48 (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
kono
parents:
diff changeset
49 pragma Ordered (Day_Name);
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 subtype Hour_Number is Natural range 0 .. 23;
kono
parents:
diff changeset
52 subtype Minute_Number is Natural range 0 .. 59;
kono
parents:
diff changeset
53 subtype Second_Number is Natural range 0 .. 59;
kono
parents:
diff changeset
54 subtype Second_Duration is Ada.Calendar.Day_Duration range 0.0 .. 1.0;
kono
parents:
diff changeset
55 subtype Day_In_Year_Number is Positive range 1 .. 366;
kono
parents:
diff changeset
56 subtype Week_In_Year_Number is Positive range 1 .. 53;
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 No_Time : constant Ada.Calendar.Time;
kono
parents:
diff changeset
59 -- A constant set to the first date that can be represented by the type
kono
parents:
diff changeset
60 -- Time. It can be used to indicate an uninitialized date.
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 function Hour (Date : Ada.Calendar.Time) return Hour_Number;
kono
parents:
diff changeset
63 function Minute (Date : Ada.Calendar.Time) return Minute_Number;
kono
parents:
diff changeset
64 function Second (Date : Ada.Calendar.Time) return Second_Number;
kono
parents:
diff changeset
65 function Sub_Second (Date : Ada.Calendar.Time) return Second_Duration;
kono
parents:
diff changeset
66 -- Hour, Minute, Second and Sub_Second returns the complete time data for
kono
parents:
diff changeset
67 -- the Date (H:M:S.SS). See Ada.Calendar for Year, Month, Day accessors.
kono
parents:
diff changeset
68 -- Second_Duration precision depends on the target clock precision.
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 function Day_Of_Week (Date : Ada.Calendar.Time) return Day_Name;
kono
parents:
diff changeset
71 -- Return the day name
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 function Day_In_Year (Date : Ada.Calendar.Time) return Day_In_Year_Number;
kono
parents:
diff changeset
74 -- Return the day number in the year. (1st January is day 1 and 31st
kono
parents:
diff changeset
75 -- December is day 365 or 366 for leap year).
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 procedure Split
kono
parents:
diff changeset
78 (Date : Ada.Calendar.Time;
kono
parents:
diff changeset
79 Year : out Ada.Calendar.Year_Number;
kono
parents:
diff changeset
80 Month : out Ada.Calendar.Month_Number;
kono
parents:
diff changeset
81 Day : out Ada.Calendar.Day_Number;
kono
parents:
diff changeset
82 Hour : out Hour_Number;
kono
parents:
diff changeset
83 Minute : out Minute_Number;
kono
parents:
diff changeset
84 Second : out Second_Number;
kono
parents:
diff changeset
85 Sub_Second : out Second_Duration);
kono
parents:
diff changeset
86 -- Split a standard Ada.Calendar.Time value in date data (Year, Month, Day)
kono
parents:
diff changeset
87 -- and Time data (Hour, Minute, Second, Sub_Second).
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 procedure Split_At_Locale
kono
parents:
diff changeset
90 (Date : Ada.Calendar.Time;
kono
parents:
diff changeset
91 Year : out Ada.Calendar.Year_Number;
kono
parents:
diff changeset
92 Month : out Ada.Calendar.Month_Number;
kono
parents:
diff changeset
93 Day : out Ada.Calendar.Day_Number;
kono
parents:
diff changeset
94 Hour : out Hour_Number;
kono
parents:
diff changeset
95 Minute : out Minute_Number;
kono
parents:
diff changeset
96 Second : out Second_Number;
kono
parents:
diff changeset
97 Sub_Second : out Second_Duration);
kono
parents:
diff changeset
98 -- Split a standard Ada.Calendar.Time value in date data (Year, Month, Day)
kono
parents:
diff changeset
99 -- and Time data (Hour, Minute, Second, Sub_Second). This version of Split
kono
parents:
diff changeset
100 -- utilizes the time zone and DST bias of the locale (equivalent to Clock).
kono
parents:
diff changeset
101 -- Due to this simplified behavior, the implementation does not require
kono
parents:
diff changeset
102 -- expensive system calls on targets such as Windows.
kono
parents:
diff changeset
103 -- WARNING: Split_At_Locale is no longer aware of historic events and may
kono
parents:
diff changeset
104 -- produce inaccurate results over DST changes which occurred in the past.
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 function Time_Of
kono
parents:
diff changeset
107 (Year : Ada.Calendar.Year_Number;
kono
parents:
diff changeset
108 Month : Ada.Calendar.Month_Number;
kono
parents:
diff changeset
109 Day : Ada.Calendar.Day_Number;
kono
parents:
diff changeset
110 Hour : Hour_Number;
kono
parents:
diff changeset
111 Minute : Minute_Number;
kono
parents:
diff changeset
112 Second : Second_Number;
kono
parents:
diff changeset
113 Sub_Second : Second_Duration := 0.0) return Ada.Calendar.Time;
kono
parents:
diff changeset
114 -- Return an Ada.Calendar.Time data built from the date and time values
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 function Time_Of_At_Locale
kono
parents:
diff changeset
117 (Year : Ada.Calendar.Year_Number;
kono
parents:
diff changeset
118 Month : Ada.Calendar.Month_Number;
kono
parents:
diff changeset
119 Day : Ada.Calendar.Day_Number;
kono
parents:
diff changeset
120 Hour : Hour_Number;
kono
parents:
diff changeset
121 Minute : Minute_Number;
kono
parents:
diff changeset
122 Second : Second_Number;
kono
parents:
diff changeset
123 Sub_Second : Second_Duration := 0.0) return Ada.Calendar.Time;
kono
parents:
diff changeset
124 -- Return an Ada.Calendar.Time data built from the date and time values.
kono
parents:
diff changeset
125 -- This version of Time_Of utilizes the time zone and DST bias of the
kono
parents:
diff changeset
126 -- locale (equivalent to Clock). Due to this simplified behavior, the
kono
parents:
diff changeset
127 -- implementation does not require expensive system calls on targets such
kono
parents:
diff changeset
128 -- as Windows.
kono
parents:
diff changeset
129 -- WARNING: Split_At_Locale is no longer aware of historic events and may
kono
parents:
diff changeset
130 -- produce inaccurate results over DST changes which occurred in the past.
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 function Week_In_Year (Date : Ada.Calendar.Time) return Week_In_Year_Number;
kono
parents:
diff changeset
133 -- Return the week number as defined in ISO 8601. A week always starts on
kono
parents:
diff changeset
134 -- a Monday and the first week of a particular year is the one containing
kono
parents:
diff changeset
135 -- the first Thursday. A year may have 53 weeks when January 1st is a
kono
parents:
diff changeset
136 -- Wednesday and the year is leap or January 1st is a Thursday. Note that
kono
parents:
diff changeset
137 -- the last days of December may belong to the first week on the next year
kono
parents:
diff changeset
138 -- and conversely, the first days of January may belong to the last week
kono
parents:
diff changeset
139 -- of the last year.
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 procedure Year_Week_In_Year
kono
parents:
diff changeset
142 (Date : Ada.Calendar.Time;
kono
parents:
diff changeset
143 Year : out Ada.Calendar.Year_Number;
kono
parents:
diff changeset
144 Week : out Week_In_Year_Number);
kono
parents:
diff changeset
145 -- Return the week number as defined in ISO 8601 along with the year in
kono
parents:
diff changeset
146 -- which the week occurs.
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 -- C timeval conversion
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 -- C timeval represent a duration (used in Select for example). This
kono
parents:
diff changeset
151 -- structure is composed of a number of seconds and a number of micro
kono
parents:
diff changeset
152 -- seconds. The timeval structure is not exposed here because its
kono
parents:
diff changeset
153 -- definition is target dependent. Interface to C programs is done via a
kono
parents:
diff changeset
154 -- pointer to timeval structure.
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 type timeval is private;
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 function To_Duration (T : not null access timeval) return Duration;
kono
parents:
diff changeset
159 function To_Timeval (D : Duration) return timeval;
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 private
kono
parents:
diff changeset
162 -- This is a dummy declaration that should be the largest possible timeval
kono
parents:
diff changeset
163 -- structure of all supported targets.
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 type timeval is array (1 .. 3) of Interfaces.C.long;
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 function Julian_Day
kono
parents:
diff changeset
168 (Year : Ada.Calendar.Year_Number;
kono
parents:
diff changeset
169 Month : Ada.Calendar.Month_Number;
kono
parents:
diff changeset
170 Day : Ada.Calendar.Day_Number) return Integer;
kono
parents:
diff changeset
171 -- Compute Julian day number
kono
parents:
diff changeset
172 --
kono
parents:
diff changeset
173 -- The code of this function is a modified version of algorithm 199 from
kono
parents:
diff changeset
174 -- the Collected Algorithms of the ACM. The author of algorithm 199 is
kono
parents:
diff changeset
175 -- Robert G. Tantzen.
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 No_Time : constant Ada.Calendar.Time :=
kono
parents:
diff changeset
178 Ada.Calendar.Formatting.Time_Of
kono
parents:
diff changeset
179 (Ada.Calendar.Year_Number'First,
kono
parents:
diff changeset
180 Ada.Calendar.Month_Number'First,
kono
parents:
diff changeset
181 Ada.Calendar.Day_Number'First,
kono
parents:
diff changeset
182 Time_Zone => 0);
kono
parents:
diff changeset
183 -- Use Time_Zone => 0 to be the same binary representation in any timezone
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 end GNAT.Calendar;