OSDN Git Service

Fix typo in previous patch.
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-calfor.adb
index b8a8c01..10e9617 100644 (file)
@@ -6,25 +6,23 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---            Copyright (C) 2006, Free Software Foundation, Inc.            --
+--          Copyright (C) 2006-2009, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
--- ware  Foundation;  either version 2,  or (at your option) any later ver- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
--- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
--- for  more details.  You should have  received  a copy of the GNU General --
--- Public License  distributed with GNAT;  see file COPYING.  If not, write --
--- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
--- MA 02111-1307, USA.                                                      --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
 --                                                                          --
--- As a special exception,  if other files  instantiate  generics from this --
--- unit, or you link  this unit with other files  to produce an executable, --
--- this  unit  does not  by itself cause  the resulting  executable  to  be --
--- covered  by the  GNU  General  Public  License.  This exception does not --
--- however invalidate  any other reasons why  the executable file  might be --
--- covered by the  GNU Public License.                                      --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
+--                                                                          --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
 --                                                                          --
 -- GNAT was originally developed  by the GNAT team at  New York University. --
 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
@@ -45,7 +43,7 @@ package body Ada.Calendar.Formatting is
 
    procedure Check_Char (S : String; C : Character; Index : Integer);
    --  Subsidiary to the two versions of Value. Determine whether the
-   --  input strint S has character C at position Index. Raise
+   --  input string S has character C at position Index. Raise
    --  Constraint_Error if there is a mismatch.
 
    procedure Check_Digit (S : String; Index : Integer);
@@ -93,6 +91,8 @@ package body Ada.Calendar.Formatting is
       Ss : Second_Duration;
       Le : Boolean;
 
+      pragma Unreferenced (Y, Mo, H, Mi);
+
    begin
       Split (Date, Y, Mo, D, H, Mi, Se, Ss, Le, Time_Zone);
       return D;
@@ -124,6 +124,8 @@ package body Ada.Calendar.Formatting is
       Ss : Second_Duration;
       Le : Boolean;
 
+      pragma Unreferenced (Y, Mo, D, Mi);
+
    begin
       Split (Date, Y, Mo, D, H, Mi, Se, Ss, Le, Time_Zone);
       return H;
@@ -140,14 +142,41 @@ package body Ada.Calendar.Formatting is
       Hour       : Hour_Number;
       Minute     : Minute_Number;
       Second     : Second_Number;
-      Sub_Second : Second_Duration;
+      Sub_Second : Duration;
       SS_Nat     : Natural;
 
-      Result : String := "00:00:00.00";
+      Low  : Integer;
+      High : Integer;
+
+      Result : String := "-00:00:00.00";
 
    begin
-      Split (Elapsed_Time, Hour, Minute, Second, Sub_Second);
-      SS_Nat := Natural (Sub_Second * 100.0);
+      Split (abs (Elapsed_Time), Hour, Minute, Second, Sub_Second);
+
+      --  Determine the two slice bounds for the result string depending on
+      --  whether the input is negative and whether fractions are requested.
+
+      if Elapsed_Time < 0.0 then
+         Low := 1;
+      else
+         Low := 2;
+      end if;
+
+      if Include_Time_Fraction then
+         High := 12;
+      else
+         High := 9;
+      end if;
+
+      --  Prevent rounding when converting to natural
+
+      Sub_Second := Sub_Second * 100.0;
+
+      if Sub_Second > 0.0 then
+         Sub_Second := Sub_Second - 0.5;
+      end if;
+
+      SS_Nat := Natural (Sub_Second);
 
       declare
          Hour_Str   : constant String := Hour_Number'Image (Hour);
@@ -156,47 +185,45 @@ package body Ada.Calendar.Formatting is
          SS_Str     : constant String := Natural'Image (SS_Nat);
 
       begin
-         --  Hour processing, positions 1 and 2
+         --  Hour processing, positions 2 and 3
 
          if Hour < 10 then
-            Result (2) := Hour_Str (2);
+            Result (3) := Hour_Str (2);
          else
-            Result (1) := Hour_Str (2);
-            Result (2) := Hour_Str (3);
+            Result (2) := Hour_Str (2);
+            Result (3) := Hour_Str (3);
          end if;
 
-         --  Minute processing, positions 4 and 5
+         --  Minute processing, positions 5 and 6
 
          if Minute < 10 then
-            Result (5) := Minute_Str (2);
+            Result (6) := Minute_Str (2);
          else
-            Result (4) := Minute_Str (2);
-            Result (5) := Minute_Str (3);
+            Result (5) := Minute_Str (2);
+            Result (6) := Minute_Str (3);
          end if;
 
-         --  Second processing, positions 7 and 8
+         --  Second processing, positions 8 and 9
 
          if Second < 10 then
-            Result (8) := Second_Str (2);
+            Result (9) := Second_Str (2);
          else
-            Result (7) := Second_Str (2);
-            Result (8) := Second_Str (3);
+            Result (8) := Second_Str (2);
+            Result (9) := Second_Str (3);
          end if;
 
-         --  Optional sub second processing, positions 10 and 11
+         --  Optional sub second processing, positions 11 and 12
 
          if Include_Time_Fraction then
             if SS_Nat < 10 then
-               Result (11) := SS_Str (2);
+               Result (12) := SS_Str (2);
             else
-               Result (10) := SS_Str (2);
-               Result (11) := SS_Str (3);
+               Result (11) := SS_Str (2);
+               Result (12) := SS_Str (3);
             end if;
-
-            return Result;
-         else
-            return Result (1 .. 8);
          end if;
+
+         return Result (Low .. High);
       end;
    end Image;
 
@@ -215,7 +242,7 @@ package body Ada.Calendar.Formatting is
       Hour        : Hour_Number;
       Minute      : Minute_Number;
       Second      : Second_Number;
-      Sub_Second  : Second_Duration;
+      Sub_Second  : Duration;
       SS_Nat      : Natural;
       Leap_Second : Boolean;
 
@@ -225,7 +252,15 @@ package body Ada.Calendar.Formatting is
       Split (Date, Year, Month, Day,
              Hour, Minute, Second, Sub_Second, Leap_Second, Time_Zone);
 
-      SS_Nat := Natural (Sub_Second * 100.0);
+      --  Prevent rounding when converting to natural
+
+      Sub_Second := Sub_Second * 100.0;
+
+      if Sub_Second > 0.0 then
+         Sub_Second := Sub_Second - 0.5;
+      end if;
+
+      SS_Nat := Natural (Sub_Second);
 
       declare
          Year_Str   : constant String := Year_Number'Image (Year);
@@ -322,6 +357,9 @@ package body Ada.Calendar.Formatting is
       Se : Second_Number;
       Ss : Second_Duration;
       Le : Boolean;
+
+      pragma Unreferenced (Y, Mo, D, H);
+
    begin
       Split (Date, Y, Mo, D, H, Mi, Se, Ss, Le, Time_Zone);
       return Mi;
@@ -343,6 +381,9 @@ package body Ada.Calendar.Formatting is
       Se : Second_Number;
       Ss : Second_Duration;
       Le : Boolean;
+
+      pragma Unreferenced (Y, D, H, Mi);
+
    begin
       Split (Date, Y, Mo, D, H, Mi, Se, Ss, Le, Time_Zone);
       return Mo;
@@ -361,6 +402,9 @@ package body Ada.Calendar.Formatting is
       Se : Second_Number;
       Ss : Second_Duration;
       Le : Boolean;
+
+      pragma Unreferenced (Y, Mo, D, H, Mi);
+
    begin
       Split (Date, Y, Mo, D, H, Mi, Se, Ss, Le);
       return Se;
@@ -390,7 +434,7 @@ package body Ada.Calendar.Formatting is
       return Day_Duration (Hour   * 3_600) +
              Day_Duration (Minute *    60) +
              Day_Duration (Second)         +
-                           Sub_Second;
+             Sub_Second;
    end Seconds_Of;
 
    -----------
@@ -590,6 +634,9 @@ package body Ada.Calendar.Formatting is
       Se : Second_Number;
       Ss : Second_Duration;
       Le : Boolean;
+
+      pragma Unreferenced (Y, Mo, D, H, Mi);
+
    begin
       Split (Date, Y, Mo, D, H, Mi, Se, Ss, Le);
       return Ss;
@@ -900,6 +947,8 @@ package body Ada.Calendar.Formatting is
       Ss : Second_Duration;
       Le : Boolean;
 
+      pragma Unreferenced (Mo, D, H, Mi);
+
    begin
       Split (Date, Y, Mo, D, H, Mi, Se, Ss, Le, Time_Zone);
       return Y;