Index: src/natools-time_io-rfc_3339.adb ================================================================== --- src/natools-time_io-rfc_3339.adb +++ src/natools-time_io-rfc_3339.adb @@ -81,24 +81,27 @@ -- Time To String -- -------------------- function Image (Date : Ada.Calendar.Time; - Subsecond_Digits : Natural := 0) + Subsecond_Digits : Natural := 0; + Force_Leap_Second : Boolean := False) return String is begin return Image (Date, Ada.Calendar.Time_Zones.UTC_Time_Offset (Date), - Subsecond_Digits); + Subsecond_Digits, + Force_Leap_Second); end Image; function Image (Date : Ada.Calendar.Time; Time_Zone : Ada.Calendar.Time_Zones.Time_Offset; - Subsecond_Digits : Natural := 0) + Subsecond_Digits : Natural := 0; + Force_Leap_Second : Boolean := False) return String is function Subsecond_Image (Subsecond : Ada.Calendar.Formatting.Second_Duration) return String; @@ -178,11 +181,11 @@ Hour, Minute, Second, Subsecond, Leap_Second, Time_Zone); - if Leap_Second then + if Leap_Second or Force_Leap_Second then pragma Assert (Second = 59); Used_Second := 60; else Used_Second := Second; end if; @@ -229,18 +232,29 @@ procedure Value (Image : in String; Date : out Ada.Calendar.Time; Time_Zone : out Ada.Calendar.Time_Zones.Time_Offset) is + Discarded : Boolean; + begin + Value (Image, Date, Time_Zone, Discarded); + end Value; + + + procedure Value + (Image : in String; + Date : out Ada.Calendar.Time; + Time_Zone : out Ada.Calendar.Time_Zones.Time_Offset; + Leap_Second : out Boolean) + is Year : Ada.Calendar.Year_Number; Month : Ada.Calendar.Month_Number; Day : Ada.Calendar.Day_Number; Hour : Ada.Calendar.Formatting.Hour_Number; Minute : Ada.Calendar.Formatting.Minute_Number; Second : Ada.Calendar.Formatting.Second_Number; Subsecond : Ada.Calendar.Formatting.Second_Duration := 0.0; - Leap_Second : Boolean; begin Year := Natural'Value (Image (Image'First .. Image'First + 3)); Month := Natural'Value (Image (Image'First + 5 .. Image'First + 6)); Day := Natural'Value (Image (Image'First + 8 .. Image'First + 9)); Hour := Natural'Value (Image (Image'First + 11 .. Image'First + 12)); @@ -253,10 +267,11 @@ begin if Number = 60 then Leap_Second := True; Second := 59; else + Leap_Second := False; Second := Number; end if; end; if Image (Image'First + 19) = Subsecond_Separator then @@ -287,13 +302,26 @@ when others => raise Constraint_Error with "Invalid time zone separator in RFC 3339 date"; end case; end if; + + if Leap_Second then + begin + Date := Ada.Calendar.Formatting.Time_Of + (Year, Month, Day, + Hour, Minute, Second, + Subsecond, True, Time_Zone); + return; + exception + when Ada.Calendar.Time_Error => + null; + end; + end if; Date := Ada.Calendar.Formatting.Time_Of (Year, Month, Day, Hour, Minute, Second, - Subsecond, Leap_Second, Time_Zone); + Subsecond, False, Time_Zone); end Value; end Natools.Time_IO.RFC_3339; Index: src/natools-time_io-rfc_3339.ads ================================================================== --- src/natools-time_io-rfc_3339.ads +++ src/natools-time_io-rfc_3339.ads @@ -32,19 +32,21 @@ function Is_Valid (Image : String) return Boolean; -- Check whether Image is a valid RFC-3339 date function Image (Date : Ada.Calendar.Time; - Subsecond_Digits : Natural := 0) + Subsecond_Digits : Natural := 0; + Force_Leap_Second : Boolean := False) return String with Post => Is_Valid (Image'Result); -- Return the RFC-3339 representation of Date in current time zone function Image (Date : Ada.Calendar.Time; Time_Zone : Ada.Calendar.Time_Zones.Time_Offset; - Subsecond_Digits : Natural := 0) + Subsecond_Digits : Natural := 0; + Force_Leap_Second : Boolean := False) return String with Post => Is_Valid (Image'Result); -- Return the RFC-3339 representation of Date in Time_Zone function Value (Image : String) return Ada.Calendar.Time @@ -53,9 +55,17 @@ procedure Value (Image : in String; Date : out Ada.Calendar.Time; Time_Zone : out Ada.Calendar.Time_Zones.Time_Offset) + with Pre => Is_Valid (Image) or else raise Constraint_Error; + -- Return the time associated with the given RFC-3339 representation + + procedure Value + (Image : in String; + Date : out Ada.Calendar.Time; + Time_Zone : out Ada.Calendar.Time_Zones.Time_Offset; + Leap_Second : out Boolean) with Pre => Is_Valid (Image) or else raise Constraint_Error; -- Return the time associated with the given RFC-3339 representation end Natools.Time_IO.RFC_3339;