diff options
author | Bob Duff <duff@adacore.com> | 2020-05-08 18:37:50 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2020-07-06 07:35:26 -0400 |
commit | b1e78e8577fcab0c0854f9b7884d6ce3290827ed (patch) | |
tree | 6d7be26479878505bff0245471c9d4e0988db5cb /gcc | |
parent | 58d94a32b4cfe6065b736cac38f73d9a8deaa5d4 (diff) | |
download | gcc-b1e78e8577fcab0c0854f9b7884d6ce3290827ed.zip gcc-b1e78e8577fcab0c0854f9b7884d6ce3290827ed.tar.gz gcc-b1e78e8577fcab0c0854f9b7884d6ce3290827ed.tar.bz2 |
[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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/libgnat/g-catiio.adb | 23 | ||||
-rw-r--r-- | 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 8011d34..5785483 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; @@ -210,6 +208,27 @@ package body GNAT.Calendar.Time_IO is ----------- 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 is diff --git a/gcc/ada/libgnat/g-catiio.ads b/gcc/ada/libgnat/g-catiio.ads index 1b76eac..85b9bb6 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 |