summaryrefslogtreecommitdiff
path: root/gcc/ada/g-catiio.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2006-02-15 09:40:43 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2006-02-15 09:40:43 +0000
commit6334b49591cee47fbe1ae1794a4c25c577976b5e (patch)
treeeb03e50c6e5a8bb096f991e32ddb4a782cc95d83 /gcc/ada/g-catiio.adb
parent6a7786f08730a608aa12e8e26b6acf4434dd300e (diff)
downloadgcc-6334b49591cee47fbe1ae1794a4c25c577976b5e.tar.gz
2006-02-13 Pascal Obry <obry@adacore.com>
* g-catiio.adb (Sec_Number): New type used to compute the number of seconds since 1-1-1970. (Image) [Natural]: The parameter was an Integer, as we can't deal with negative numbers (years, months...) it is better to have a Natural here. Code clean-up. (Image) [Number]: Change parameter from Long_Integer to Number. (Image): Use Number type to compute the seconds since 1-1-1970 to fix an overflow for dates past year 2038. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111072 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/g-catiio.adb')
-rw-r--r--gcc/ada/g-catiio.adb31
1 files changed, 19 insertions, 12 deletions
diff --git a/gcc/ada/g-catiio.adb b/gcc/ada/g-catiio.adb
index fe996be4328..4d0a49cbfa8 100644
--- a/gcc/ada/g-catiio.adb
+++ b/gcc/ada/g-catiio.adb
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 1999-2005, AdaCore --
+-- Copyright (C) 1999-2006, AdaCore --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. The copyright notice above, and the license provisions that follow --
@@ -58,6 +58,12 @@ package body GNAT.Calendar.Time_IO is
type Padding_Mode is (None, Zero, Space);
+ type Sec_Number is mod 2 ** 64;
+ -- Type used to compute the number of seconds since 01/01/1970. A 32 bit
+ -- number will cover only a period of 136 years. This means that for date
+ -- past 2106 the computation is not possible. A 64 bits number should be
+ -- enough for a very large period of time.
+
-----------------------
-- Local Subprograms --
-----------------------
@@ -73,14 +79,14 @@ package body GNAT.Calendar.Time_IO is
-- length is set to 0 it does not cut it.
function Image
- (N : Long_Integer;
+ (N : Sec_Number;
Padding : Padding_Mode := Zero;
Length : Natural := 0) return String;
-- Return image of N. This number is eventually padded with zeros or spaces
-- depending of the length required. If length is 0 then no padding occurs.
function Image
- (N : Integer;
+ (N : Natural;
Padding : Padding_Mode := Zero;
Length : Natural := 0) return String;
-- As above with N provided in Integer format
@@ -137,16 +143,16 @@ package body GNAT.Calendar.Time_IO is
-----------
function Image
- (N : Integer;
+ (N : Natural;
Padding : Padding_Mode := Zero;
Length : Natural := 0) return String
is
begin
- return Image (Long_Integer (N), Padding, Length);
+ return Image (Sec_Number (N), Padding, Length);
end Image;
function Image
- (N : Long_Integer;
+ (N : Sec_Number;
Padding : Padding_Mode := Zero;
Length : Natural := 0) return String
is
@@ -165,7 +171,7 @@ package body GNAT.Calendar.Time_IO is
end case;
end Pad_Char;
- NI : constant String := Long_Integer'Image (N);
+ NI : constant String := Sec_Number'Image (N);
NIP : constant String := Pad_Char & NI (2 .. NI'Last);
-- Start of processing for Image
@@ -290,11 +296,12 @@ package body GNAT.Calendar.Time_IO is
when 's' =>
declare
- Sec : constant Long_Integer :=
- Long_Integer
- ((Julian_Day (Year, Month, Day) -
- Julian_Day (1970, 1, 1)) * 86_400 +
- Hour * 3_600 + Minute * 60 + Second);
+ Sec : constant Sec_Number :=
+ Sec_Number (Julian_Day (Year, Month, Day) -
+ Julian_Day (1970, 1, 1)) * 86_400
+ + Sec_Number (Hour) * 3_600
+ + Sec_Number (Minute) * 60
+ + Sec_Number (Second);
begin
Result := Result & Image (Sec, None);