summaryrefslogtreecommitdiff
path: root/gcc/ada/g-catiio.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2007-08-14 08:47:45 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2007-08-14 08:47:45 +0000
commit7320c67896d0cbd2b515237bd92b57de616b7f02 (patch)
treea400013a9a93fbd7182e987420beb5dc83c31ca0 /gcc/ada/g-catiio.adb
parentcf8e0304120ae51d08e6beb5b0914494a71c4d95 (diff)
downloadgcc-7320c67896d0cbd2b515237bd92b57de616b7f02.tar.gz
2007-08-14 Hristian Kirtchev <kirtchev@adacore.com>
* g-catiio.adb (Image): For the case of %s, use Ada.Calendar.Time values to compute the number of seconds since the Unix Epoc in order to account for Daylight Savings Time. Perform special processing for dates that are earlier than the Unix Epoc to obtain a negative number. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@127450 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/g-catiio.adb')
-rw-r--r--gcc/ada/g-catiio.adb32
1 files changed, 25 insertions, 7 deletions
diff --git a/gcc/ada/g-catiio.adb b/gcc/ada/g-catiio.adb
index f0174d5266a..5286ef034d1 100644
--- a/gcc/ada/g-catiio.adb
+++ b/gcc/ada/g-catiio.adb
@@ -306,15 +306,33 @@ package body GNAT.Calendar.Time_IO is
when 's' =>
declare
- 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);
+ -- Compute the number of seconds using Ada.Calendar.Time
+ -- values rather than Julian days to account for Daylight
+ -- Savings Time.
+
+ Neg : Boolean := False;
+ Sec : Duration := Date - Time_Of (1970, 1, 1, 0.0);
begin
- Result := Result & Image (Sec, None);
+ -- Avoid rounding errors and perform special processing
+ -- for dates earlier than the Unix Epoc.
+
+ if Sec > 0.0 then
+ Sec := Sec - 0.5;
+ elsif Sec < 0.0 then
+ Neg := True;
+ Sec := abs (Sec + 0.5);
+ end if;
+
+ -- Prepend a minus sign to the result since Sec_Number
+ -- cannot handle negative numbers.
+
+ if Neg then
+ Result :=
+ Result & "-" & Image (Sec_Number (Sec), None);
+ else
+ Result := Result & Image (Sec_Number (Sec), None);
+ end if;
end;
-- Second (00..59)