aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/a-calend-vms.ads
diff options
context:
space:
mode:
authorHristian Kirtchev <kirtchev@adacore.com>2007-04-06 11:15:21 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2007-04-06 11:15:21 +0200
commit42907632860e44cc8c8b49a0b74444f62791fb9c (patch)
tree7a061f08c1577dcad5f77bb59e183a711e8af6e1 /gcc/ada/a-calend-vms.ads
parent3d3bf932b985baee7ac3973208c0d775dcb93b5d (diff)
downloadgcc-42907632860e44cc8c8b49a0b74444f62791fb9c.zip
gcc-42907632860e44cc8c8b49a0b74444f62791fb9c.tar.gz
gcc-42907632860e44cc8c8b49a0b74444f62791fb9c.tar.bz2
a-calend-vms.ads, [...]: New version of Ada.Calendar which supports the new upper bound of Ada time...
2007-04-06 Hristian Kirtchev <kirtchev@adacore.com> Vincent Celier <celier@adacore.com> * a-calend-vms.ads, a-calend.ads, a-calend.adb, a-calend-vms.adb: New version of Ada.Calendar which supports the new upper bound of Ada time (2399-12-31 86_399.999999999). The following modifications have been made to the package: - New representation of time as count of nanoseconds since the start of Ada time (1901-1-1 0.0). - Target independent Split and Time_Of routines which service both Ada 95 and Ada 2005 code. - Target independent interface to the Ada 2005 children of Calendar. - Integrated leap seconds into Ada 95 and Ada 2005 mode. - Handling of non-leap centenial years. - Updated clock function. - Updated arithmetic and comparison operators. * a-caldel.adb (To_Duration): Add call to target independent routine in Ada.Calendar to handle the conversion of time to duration. * sysdep.c (__gnat_localtime_tzoff): Test timezone before setting off (UTC Offset). If timezone is obviously incorrect (outside of -14 hours .. 14 hours), set off to 0. (__gnat_localtime_tzoff for Lynx and VxWorks): Even though these targets do not have a natural time zone, GMT is used as a default. (__gnat_get_task_options): New. * a-direct.adb (Modification_Time): Add with and use clauses for Ada.Calendar and Ada. Calendar.Formatting. Remove with clause for Ada.Unchecked_Conversion since it is no longer needed. (Duration_To_Time): Removed. (OS_Time_To_Long_Integer): Removed. (Modification_Time): Rewritten to use Ada.Calendar and Ada.Calendar. Formatting Time_Of routines which automatically handle time zones, buffer periods and leap seconds. * a-calari.ads, a-calari.adb ("+", "-", Difference): Add calls to target independent routines in Ada.Calendar. * a-calfor.ads, a-calfor.adb: Code cleanup and addition of validity checks in various routines. (Day_Of_Week, Split, Time_Of): Add call to target independent routine in Ada.Calendar. * a-catizo.ads, a-catizo.adb (UTC_Time_Offset): Add call to target independent routine in Ada.Calendar. From-SVN: r123543
Diffstat (limited to 'gcc/ada/a-calend-vms.ads')
-rw-r--r--gcc/ada/a-calend-vms.ads175
1 files changed, 99 insertions, 76 deletions
diff --git a/gcc/ada/a-calend-vms.ads b/gcc/ada/a-calend-vms.ads
index 3f68ffb..6fc05f3 100644
--- a/gcc/ada/a-calend-vms.ads
+++ b/gcc/ada/a-calend-vms.ads
@@ -44,11 +44,12 @@ package Ada.Calendar is
type Time is private;
- -- Declarations representing limits of allowed local time values. Note that
- -- these do NOT constrain the possible stored values of time which may well
- -- permit a larger range of times (this is explicitly allowed in Ada 95).
+ -- Declarations representing limits of allowed local time values. Note
+ -- that these do NOT constrain the possible stored values of time which
+ -- may well permit a larger range of times (this is explicitly allowed
+ -- in Ada 95).
- subtype Year_Number is Integer range 1901 .. 2099;
+ subtype Year_Number is Integer range 1901 .. 2399;
subtype Month_Number is Integer range 1 .. 12;
subtype Day_Number is Integer range 1 .. 31;
@@ -72,8 +73,7 @@ package Ada.Calendar is
(Year : Year_Number;
Month : Month_Number;
Day : Day_Number;
- Seconds : Day_Duration := 0.0)
- return Time;
+ Seconds : Day_Duration := 0.0) return Time;
function "+" (Left : Time; Right : Duration) return Time;
function "+" (Left : Duration; Right : Time) return Time;
@@ -87,10 +87,7 @@ package Ada.Calendar is
Time_Error : exception;
- Unimplemented : exception;
-
private
-
pragma Inline (Clock);
pragma Inline (Year);
@@ -105,81 +102,107 @@ private
pragma Inline (">");
pragma Inline (">=");
- -- Time is represented as the number of 100-nanosecond (ns) units offset
- -- from the system base date and time, which is 00:00 o'clock,
- -- November 17, 1858 (the Smithsonian base date and time for the
- -- astronomic calendar).
+ -- Although the units are 100 nanoseconds, for the purpose of better
+ -- readability, this unit will be called "mili".
+
+ Mili : constant := 10_000_000;
+ Milis_In_Day : constant := 864_000_000_000;
+ Secs_In_Day : constant := 86_400;
+
+ -- Time is represented as the number of 100-nanosecond (ns) units from the
+ -- system base date and time 1858-11-17 0.0 (the Smithsonian base date and
+ -- time for the astronomic calendar).
-- The time value stored is typically a GMT value, as provided in standard
-- Unix environments. If this is the case then Split and Time_Of perform
-- required conversions to and from local times.
- type Time is new OSP.OS_Time;
-
-- Notwithstanding this definition, Time is not quite the same as OS_Time.
-- Relative Time is positive, whereas relative OS_Time is negative,
-- but this declaration makes for easier conversion.
- -- The following package provides handling of leap seconds. It is
- -- used by Ada.Calendar.Arithmetic and Ada.Calendar.Formatting, both
- -- Ada 2005 children of Ada.Calendar.
-
- package Leap_Sec_Ops is
-
- After_Last_Leap : constant Time := Time'Last;
- -- Bigger by far than any leap second value. Not within range of
- -- Ada.Calendar specified dates.
-
- procedure Cumulative_Leap_Secs
- (Start_Date : Time;
- End_Date : Time;
- Leaps_Between : out Duration;
- Next_Leap_Sec : out Time);
- -- Leaps_Between is the sum of the leap seconds that have occured
- -- on or after Start_Date and before (strictly before) End_Date.
- -- Next_Leap_Sec represents the next leap second occurence on or
- -- after End_Date. If there are no leaps seconds after End_Date,
- -- After_Last_Leap is returned. This does not provide info about
- -- the next leap second (pos/neg or ?). After_Last_Leap can be used
- -- as End_Date to count all the leap seconds that have occured on
- -- or after Start_Date.
- --
- -- Important Notes: any fractional parts of Start_Date and End_Date
- -- are discarded before the calculations are done. For instance: if
- -- 113 seconds is a leap second (it isn't) and 113.5 is input as an
- -- End_Date, the leap second at 113 will not be counted in
- -- Leaps_Between, but it will be returned as Next_Leap_Sec. Thus, if
- -- the caller wants to know if the End_Date is a leap second, the
- -- comparison should be:
- --
- -- End_Date >= Next_Leap_Sec;
- --
- -- After_Last_Leap is designed so that this comparison works without
- -- having to first check if Next_Leap_Sec is a valid leap second.
-
- function All_Leap_Seconds return Duration;
- -- Returns the sum off all of the leap seoncds.
-
- end Leap_Sec_Ops;
-
- procedure Split_With_Offset
- (Date : Time;
- Year : out Year_Number;
- Month : out Month_Number;
- Day : out Day_Number;
- Seconds : out Day_Duration;
- Offset : out Long_Integer);
- -- Split_W_Offset has the same spec as Split with the addition of an
- -- offset value which give the offset of the local time zone from UTC
- -- at the input Date. This value comes for free during the implementation
- -- of Split and is needed by UTC_Time_Offset. The returned Offset time
- -- is straight from the C tm struct and is in seconds. If the system
- -- dependent code has no way to find the offset it will return the value
- -- Invalid_TZ_Offset declared below. Otherwise no checking is done, so
- -- it is up to the user to check both for Invalid_TZ_Offset and otherwise
- -- for a value that is acceptable.
-
- Invalid_TZ_Offset : Long_Integer;
- pragma Import (C, Invalid_TZ_Offset, "__gnat_invalid_tzoff");
+ type Time is new OSP.OS_Time;
+
+ -- The range of Ada time expressed as milis since the VMS Epoch
+
+ Ada_Low : constant Time := (10 * 366 + 32 * 365 + 45) * Milis_In_Day;
+ Ada_High : constant Time := (131 * 366 + 410 * 365 + 45) * Milis_In_Day;
+
+ Days_In_Month : constant array (Month_Number) of Day_Number :=
+ (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
+
+ Invalid_Time_Zone_Offset : Long_Integer;
+ pragma Import (C, Invalid_Time_Zone_Offset, "__gnat_invalid_tzoff");
+
+ function Is_Leap (Year : Year_Number) return Boolean;
+ -- Determine whether a given year is leap
+
+ -- The following packages provide a target independent interface to the
+ -- children of Calendar - Arithmetic, Formatting and Time_Zones.
+
+ -- NOTE: Delays does not need a target independent interface because
+ -- VMS already has a target specific file for that package.
+
+ package Arithmetic_Operations is
+ function Add (Date : Time; Days : Long_Integer) return Time;
+ -- Add X number of days to a time value
+
+ procedure Difference
+ (Left : Time;
+ Right : Time;
+ Days : out Long_Integer;
+ Seconds : out Duration;
+ Leap_Seconds : out Integer);
+ -- Calculate the difference between two time values in terms of days,
+ -- seconds and leap seconds elapsed. The leap seconds are not included
+ -- in the seconds returned. If Left is greater than Right, the returned
+ -- values are positive, negative otherwise.
+
+ function Subtract (Date : Time; Days : Long_Integer) return Time;
+ -- Subtract X number of days from a time value
+ end Arithmetic_Operations;
+
+ package Formatting_Operations is
+ function Day_Of_Week (Date : Time) return Integer;
+ -- Determine which day of week Date falls on. The returned values are
+ -- within the range of 0 .. 6 (Monday .. Sunday).
+
+ procedure Split
+ (Date : Time;
+ Year : out Year_Number;
+ Month : out Month_Number;
+ Day : out Day_Number;
+ Day_Secs : out Day_Duration;
+ Hour : out Integer;
+ Minute : out Integer;
+ Second : out Integer;
+ Sub_Sec : out Duration;
+ Leap_Sec : out Boolean;
+ Time_Zone : Long_Integer);
+ -- Split a time value into its components
+
+ function Time_Of
+ (Year : Year_Number;
+ Month : Month_Number;
+ Day : Day_Number;
+ Day_Secs : Day_Duration;
+ Hour : Integer;
+ Minute : Integer;
+ Second : Integer;
+ Sub_Sec : Duration;
+ Leap_Sec : Boolean;
+ Leap_Checks : Boolean;
+ Use_Day_Secs : Boolean;
+ Time_Zone : Long_Integer) return Time;
+ -- Given all the components of a date, return the corresponding time
+ -- value. Set Use_Day_Secs to use the value in Day_Secs, otherwise the
+ -- day duration will be calculated from Hour, Minute, Second and Sub_
+ -- Sec. Set flag Leap_Checks to verify the validity of a leap second.
+ end Formatting_Operations;
+
+ package Time_Zones_Operations is
+ function UTC_Time_Offset (Date : Time) return Long_Integer;
+ -- Return the offset in seconds from GMT
+ end Time_Zones_Operations;
end Ada.Calendar;