From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id 946443857017; Mon, 6 Jul 2020 11:41:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 946443857017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1594035670; bh=rTRANNganosVngtCrFDVgAlAjOsAXsfjfiWCw3vfRGI=; h=From:To:Subject:Date:From; b=Tt73Esnu/yYVVf/Fpv70Bsozl4Nf5Z/mkAdsE/p4ine4h8ZOl0/SxiDb8SSmPFYgc qUNaKc/oiBmIlcsQnnOPu6wCnY+YO4HK8eb0N1tgIrNNsoQi99WuPrkPG8jnZ5cEh8 bnQ8XVCbYGybA/WyaUj2lmV/7q4RbjAzRfdn54Sw= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-1848] [Ada] Time_IO.Value: Allow subseconds and time zones together X-Act-Checkin: gcc X-Git-Author: Bob Duff X-Git-Refname: refs/heads/master X-Git-Oldrev: bf8467d8069a4cd91a1071431200926186235f1c X-Git-Newrev: d868231706cf9a43ce1d6b474e8c1aa1535c4736 Message-Id: <20200706114110.946443857017@sourceware.org> Date: Mon, 6 Jul 2020 11:41:10 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Jul 2020 11:41:10 -0000 https://gcc.gnu.org/g:d868231706cf9a43ce1d6b474e8c1aa1535c4736 commit r11-1848-gd868231706cf9a43ce1d6b474e8c1aa1535c4736 Author: Bob Duff Date: Sat May 9 20:23:58 2020 -0400 [Ada] Time_IO.Value: Allow subseconds and time zones together gcc/ada/ * libgnat/g-catiio.ads: Change the regular expression that documents the allowed format to match what ISO-8601 allows. * libgnat/g-catiio.adb (Scan_Subsecond): Rewrite so it doesn't assume the subsecond comes last. (Parse_ISO_8601): Parse an optional subsecond, followed by an optional time zone, rather than making these alternatives to each other. Diff: --- gcc/ada/libgnat/g-catiio.adb | 47 ++++++++++++++++++++++---------------------- gcc/ada/libgnat/g-catiio.ads | 3 ++- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/gcc/ada/libgnat/g-catiio.adb b/gcc/ada/libgnat/g-catiio.adb index 21ffc7bda33..f7bffe4e471 100644 --- a/gcc/ada/libgnat/g-catiio.adb +++ b/gcc/ada/libgnat/g-catiio.adb @@ -778,17 +778,10 @@ package body GNAT.Calendar.Time_IO is begin Advance_Digits (Num_Digits => 1); - while Symbol in '0' .. '9' - and then Index < Date'Length - loop + while Index <= Date'Length and then Symbol in '0' .. '9' loop Advance; end loop; - if Symbol not in '0' .. '9' then - raise Wrong_Syntax; - end if; - - Advance; return Second_Duration'Value ("0." & Date (From .. Index - 1)); end Scan_Subsecond; @@ -845,6 +838,8 @@ package body GNAT.Calendar.Time_IO is subtype Sign_Type is Character with Predicate => Sign_Type in '+' | '-'; + -- Start of processing for Parse_ISO_8601 + begin -- Parse date @@ -869,26 +864,31 @@ package body GNAT.Calendar.Time_IO is Second := Scan_Second; - -- [('Z' | ('.' | ',') s{s} | ('+'|'-')hh:mm)] + -- [ ('.' | ',') s{s} ] if Index <= Date'Last then - - -- Suffix 'Z' signifies that this is UTC time (time zone 0) - - if Symbol = 'Z' then - Time_Zone_Seen := True; - Time_Zone_Offset := 0; - Advance; - -- A decimal fraction shall have at least one digit, and has as -- many digits as supported by the underlying implementation. -- The valid decimal separators are those specified in ISO 31-0, -- i.e. the comma [,] or full stop [.]. Of these, the comma is -- the preferred separator of ISO-8601. - elsif Symbol = ',' or else Symbol = '.' then + if Symbol = ',' or else Symbol = '.' then Advance; -- past decimal separator Subsec := Scan_Subsecond; + end if; + end if; + + -- [ ('Z' | ('+'|'-')hh':'mm) ] + + if Index <= Date'Last then + Time_Zone_Seen := Symbol in 'Z' | Sign_Type; + + -- Suffix 'Z' signifies that this is UTC time (time zone 0) + + if Symbol = 'Z' then + Time_Zone_Offset := 0; + Advance; -- Difference between local time and UTC: It shall be expressed -- as positive (i.e. with the leading plus sign [+]) if the local @@ -900,12 +900,10 @@ package body GNAT.Calendar.Time_IO is elsif Symbol in Sign_Type then declare - Time_Zone_Sign : constant Sign_Type := Symbol; - + Time_Zone_Sign : constant Sign_Type := Symbol; Time_Zone_Hour : Hour_Number; Time_Zone_Minute : Minute_Number; begin - Time_Zone_Seen := True; Advance; Time_Zone_Hour := Scan_Hour; @@ -923,9 +921,10 @@ package body GNAT.Calendar.Time_IO is Time_Zone_Offset := Time_Offset (Time_Zone_Hour * 60 + Time_Zone_Minute); - if Time_Zone_Sign = '-' then - Time_Zone_Offset := -Time_Zone_Offset; - end if; + case Time_Zone_Sign is + when '+' => null; + when '-' => Time_Zone_Offset := -Time_Zone_Offset; + end case; end; else raise Wrong_Syntax; diff --git a/gcc/ada/libgnat/g-catiio.ads b/gcc/ada/libgnat/g-catiio.ads index 85b9bb6d952..982b80d13c3 100644 --- a/gcc/ada/libgnat/g-catiio.ads +++ b/gcc/ada/libgnat/g-catiio.ads @@ -154,7 +154,8 @@ package GNAT.Calendar.Time_IO is -- supported: -- -- (yyyymmdd | yyyy'-'mm'-'dd)'T'(hhmmss | hh':'mm':'ss) - -- [ ('Z' | ('.' | ',') s{s} | ('+'|'-')hh':'mm) ] + -- [ ('.' | ',') s{s} ] + -- [ ('Z' | ('+'|'-')hh':'mm) ] -- Trailing characters (including spaces) are not allowed. -- In the ISO case, the current time zone is not used; the time zone -- is as specified in the string, defaulting to UTC.