From b1e78e8577fcab0c0854f9b7884d6ce3290827ed Mon Sep 17 00:00:00 2001 From: Bob Duff Date: Fri, 8 May 2020 18:37:50 -0400 Subject: [PATCH] [Ada] Implement Time_IO.Image with Time_Zone gcc/ada/ * libgnat/g-catiio.ads, libgnat/g-catiio.adb (Image): New function. It might seem like the local-time Image should be implemented in terms of the Time_Zone Image, but that would be far harder to implement, so we do it the other way around. --- gcc/ada/libgnat/g-catiio.adb | 23 +++++++++++++++++++++-- gcc/ada/libgnat/g-catiio.ads | 9 +++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/gcc/ada/libgnat/g-catiio.adb b/gcc/ada/libgnat/g-catiio.adb index 8011d34d021..57854837198 100644 --- a/gcc/ada/libgnat/g-catiio.adb +++ b/gcc/ada/libgnat/g-catiio.adb @@ -29,8 +29,6 @@ -- -- ------------------------------------------------------------------------------ -with Ada.Calendar; use Ada.Calendar; -with Ada.Calendar.Time_Zones; with Ada.Characters.Handling; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Text_IO; @@ -209,6 +207,27 @@ package body GNAT.Calendar.Time_IO is -- Image -- ----------- + function Image + (Date : Ada.Calendar.Time; + Picture : Picture_String; + Time_Zone : Time_Zones.Time_Offset) return String + is + -- We subtract off the local time zone, and add in the requested + -- Time_Zone, and then pass it on to the version of Image that uses + -- the local time zone. + + use Time_Zones; + Local_TZ : constant Time_Offset := Local_Time_Offset (Date); + Minute_Offset : constant Integer := Integer (Time_Zone - Local_TZ); + Second_Offset : constant Integer := Minute_Offset * 60; + begin + return Image (Date + Duration (Second_Offset), Picture); + end Image; + + ----------- + -- Image -- + ----------- + function Image (Date : Ada.Calendar.Time; Picture : Picture_String) return String diff --git a/gcc/ada/libgnat/g-catiio.ads b/gcc/ada/libgnat/g-catiio.ads index 1b76eacbee9..85b9bb6d952 100644 --- a/gcc/ada/libgnat/g-catiio.ads +++ b/gcc/ada/libgnat/g-catiio.ads @@ -32,6 +32,8 @@ -- This package augments standard Ada.Text_IO with facilities for input -- and output of time values in standardized format. +with Ada.Calendar.Time_Zones; use Ada.Calendar; + package GNAT.Calendar.Time_IO is Picture_Error : exception; @@ -115,6 +117,13 @@ package GNAT.Calendar.Time_IO is -- with format Picture. Raise Picture_Error if picture string is null or -- has an incorrect format. + function Image + (Date : Ada.Calendar.Time; + Picture : Picture_String; + Time_Zone : Time_Zones.Time_Offset) return String; + -- Same as previous Image, except it uses the specified time zone instead + -- of the local time zone. + function Value (Date : String) return Ada.Calendar.Time; -- Parse the string Date, interpreted as a time representation in the -- current local time zone, and return the corresponding Time value. The -- 2.30.2