public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Fix edge case in Ada.Calendar.Formatting.Time_Of
@ 2023-06-20  7:46 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2023-06-20  7:46 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ronan Desplanques

From: Ronan Desplanques <desplanques@adacore.com>

Before this patch, Ada.Calendar.Formatting.Time_Of executed extra code
when passed a number of seconds equal to the number of seconds in a day.
This caused the result to be off, perhaps because a statement resetting
the number of seconds to zero was missing.

Instead of adding such a statement, this patch removes the special
handling of the problematic case, which gives the intended result.

gcc/ada/

	* libgnat/a-calfor.adb (Time_Of): Fix handling of special case.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/a-calfor.adb | 31 +++----------------------------
 1 file changed, 3 insertions(+), 28 deletions(-)

diff --git a/gcc/ada/libgnat/a-calfor.adb b/gcc/ada/libgnat/a-calfor.adb
index 3325e562746..18f4e7388df 100644
--- a/gcc/ada/libgnat/a-calfor.adb
+++ b/gcc/ada/libgnat/a-calfor.adb
@@ -590,10 +590,6 @@ package body Ada.Calendar.Formatting is
       Leap_Second : Boolean := False;
       Time_Zone   : Time_Zones.Time_Offset := 0) return Time
    is
-      Adj_Year  : Year_Number  := Year;
-      Adj_Month : Month_Number := Month;
-      Adj_Day   : Day_Number   := Day;
-
       H  : constant Integer := 1;
       M  : constant Integer := 1;
       Se : constant Integer := 1;
@@ -612,32 +608,11 @@ package body Ada.Calendar.Formatting is
          raise Constraint_Error;
       end if;
 
-      --  A Seconds value of 86_400 denotes a new day. This case requires an
-      --  adjustment to the input values.
-
-      if Seconds = 86_400.0 then
-         if Day < Days_In_Month (Month)
-           or else (Is_Leap (Year)
-                      and then Month = 2)
-         then
-            Adj_Day := Day + 1;
-         else
-            Adj_Day := 1;
-
-            if Month < 12 then
-               Adj_Month := Month + 1;
-            else
-               Adj_Month := 1;
-               Adj_Year  := Year + 1;
-            end if;
-         end if;
-      end if;
-
       return
         Formatting_Operations.Time_Of
-          (Year         => Adj_Year,
-           Month        => Adj_Month,
-           Day          => Adj_Day,
+          (Year         => Year,
+           Month        => Month,
+           Day          => Day,
            Day_Secs     => Seconds,
            Hour         => H,
            Minute       => M,
-- 
2.40.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-20  7:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-20  7:46 [COMMITTED] ada: Fix edge case in Ada.Calendar.Formatting.Time_Of Marc Poulhiès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).