X-Loop: help-debbugs@HIDDEN Subject: bug#21907: date->string duff ISO 8601 zone format Resent-From: Zefram <zefram@HIDDEN> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> Resent-CC: bug-guile@HIDDEN Resent-Date: Fri, 13 Nov 2015 15:00:03 +0000 Resent-Message-ID: <handler.21907.B.144742678113204 <at> debbugs.gnu.org> Resent-Sender: help-debbugs@HIDDEN X-GNU-PR-Message: report 21907 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 21907 <at> debbugs.gnu.org X-Debbugs-Original-To: bug-guile@HIDDEN Received: via spool by submit <at> debbugs.gnu.org id=B.144742678113204 (code B ref -1); Fri, 13 Nov 2015 15:00:03 +0000 Received: (at submit) by debbugs.gnu.org; 13 Nov 2015 14:59:41 +0000 Received: from localhost ([127.0.0.1]:37324 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1ZxFpE-0003Qu-To for submit <at> debbugs.gnu.org; Fri, 13 Nov 2015 09:59:41 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59551) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from <zefram@HIDDEN>) id 1ZxFou-0003QT-Hc for submit <at> debbugs.gnu.org; Fri, 13 Nov 2015 09:59:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <zefram@HIDDEN>) id 1ZxFot-0006gM-95 for submit <at> debbugs.gnu.org; Fri, 13 Nov 2015 09:59:20 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:47790) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <zefram@HIDDEN>) id 1ZxFot-0006gC-5n for submit <at> debbugs.gnu.org; Fri, 13 Nov 2015 09:59:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <zefram@HIDDEN>) id 1ZxFos-0008Vl-8o for bug-guile@HIDDEN; Fri, 13 Nov 2015 09:59:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <zefram@HIDDEN>) id 1ZxFor-0006eU-Bj for bug-guile@HIDDEN; Fri, 13 Nov 2015 09:59:18 -0500 Received: from river6.fysh.org ([2001:41d0:d:20da::2]:38133 helo=river.fysh.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <zefram@HIDDEN>) id 1ZxFor-0006dH-5L for bug-guile@HIDDEN; Fri, 13 Nov 2015 09:59:17 -0500 Received: from zefram by river.fysh.org with local (Exim 4.80 #2 (Debian)) id 1ZxFon-0002RE-Nu; Fri, 13 Nov 2015 14:59:13 +0000 Date: Fri, 13 Nov 2015 14:59:13 +0000 From: Zefram <zefram@HIDDEN> Message-ID: <20151113145913.GQ13455@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -4.0 (----) scheme@(guile-user)> (use-modules (srfi srfi-19)) scheme@(guile-user)> (date->string (julian-day->date 2450000 3600) "~4") $1 = "1995-10-09T13:00:00+0100" scheme@(guile-user)> (date->string (julian-day->date 2450000 3630) "~4") $2 = "1995-10-09T13:00:30+0100" There are two problems here with date->string's representation of zone offsets for the ISO 8601 formats "~2" and "~4". Firstly, because the time-of-day is represented in the extended format with colon separators, the zone offset must also be represented with colon separators. So the first "+0100" above should be "+01:00". Secondly, the offset is being truncated to an integral minute, so the output doesn't fully represent the zone offset. More importantly, because the local time-of-day isn't being adjusted to match, it's not accurately representing the point in time. ISO 8601 doesn't permit a seconds component in the zone offset, so you have a choice of three not-entirely-satisfactory options. Firstly, you could round the zone offset and adjust the represented local time accordingly, so the 3630 conversion above would yield either "1995-10-09T13:00:00+01:00" or "1995-10-09T13:01:00+01:01". Secondly, you could use the obvious extension of the ISO 8601 format to a seconds component, outputting "1995-10-09T13:00:30+01:00:30". Or finally you could signal an error when trying to represent a zone offset that's not an integral minute. Incidentally, for offsets of -1 to -59 inclusive, the truncation isn't clearing the negative sign, so is producing the invalid output "-0000". The zero offset is required to be represented with a "+" sign. If you take the rounding option described above, anything that rounds to a zero-minutes offset must yield "+00:00" in the output. -zefram
Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.503 (Entity 5.503) Content-Type: text/plain; charset=utf-8 X-Loop: help-debbugs@HIDDEN From: help-debbugs@HIDDEN (GNU bug Tracking System) To: Zefram <zefram@HIDDEN> Subject: bug#21907: Acknowledgement (date->string duff ISO 8601 zone format) Message-ID: <handler.21907.B.144742678113204.ack <at> debbugs.gnu.org> References: <20151113145913.GQ13455@HIDDEN> X-Gnu-PR-Message: ack 21907 X-Gnu-PR-Package: guile Reply-To: 21907 <at> debbugs.gnu.org Date: Fri, 13 Nov 2015 15:00:05 +0000 Thank you for filing a new bug report with debbugs.gnu.org. This is an automatically generated reply to let you know your message has been received. Your message is being forwarded to the package maintainers and other interested parties for their attention; they will reply in due course. Your message has been sent to the package maintainer(s): bug-guile@HIDDEN If you wish to submit further information on this problem, please send it to 21907 <at> debbugs.gnu.org. Please do not send mail to help-debbugs@HIDDEN unless you wish to report a problem with the Bug-tracking system. --=20 21907: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D21907 GNU Bug Tracking System Contact help-debbugs@HIDDEN with problems
X-Loop: help-debbugs@HIDDEN Subject: bug#21907: date->string duff ISO 8601 zone format Resent-From: Zefram <zefram@HIDDEN> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> Resent-CC: bug-guile@HIDDEN Resent-Date: Wed, 19 Apr 2017 21:22:01 +0000 Resent-Message-ID: <handler.21907.B21907.149263691327301 <at> debbugs.gnu.org> Resent-Sender: help-debbugs@HIDDEN X-GNU-PR-Message: followup 21907 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 21907 <at> debbugs.gnu.org Received: via spool by 21907-submit <at> debbugs.gnu.org id=B21907.149263691327301 (code B ref 21907); Wed, 19 Apr 2017 21:22:01 +0000 Received: (at 21907) by debbugs.gnu.org; 19 Apr 2017 21:21:53 +0000 Received: from localhost ([127.0.0.1]:57491 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1d0x2v-00076H-0V for submit <at> debbugs.gnu.org; Wed, 19 Apr 2017 17:21:53 -0400 Received: from river.fysh.org ([87.98.248.19]:51209 ident=Debian-exim) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <zefram@HIDDEN>) id 1d0x2r-000767-SQ for 21907 <at> debbugs.gnu.org; Wed, 19 Apr 2017 17:21:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=fysh.org; s=20170316; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date; bh=P1V5KGKUp7XtgPGAAEVhqDroqM01mpgw2/+W0D1FT/U=; b=67FNIo4KBQM2qcDHztL3tKw/np/tDDrh2LDHocicMYMzwTN/q+leG+o7rKpzZdEunPnp/jt4SJBiAstiEEkxRG8bxuXLT0s2E5djgH7f8/+eojmLgnHS8he0QJVEP55CRo8DqdsE9M2Jb9FdfMCzFej0nVRP+Yo86YroyF+O3vE=; Received: from zefram by river.fysh.org with local (Exim 4.84_2 #1 (Debian)) id 1d0x2o-000858-IQ; Wed, 19 Apr 2017 22:21:46 +0100 Date: Wed, 19 Apr 2017 22:21:46 +0100 From: Zefram <zefram@HIDDEN> Message-ID: <20170419212146.GB912@HIDDEN> References: <20151113145913.GQ13455@HIDDEN> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="4SFOXa2GPu3tIq4H" Content-Disposition: inline In-Reply-To: <20151113145913.GQ13455@HIDDEN> X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: 0.0 (/) --4SFOXa2GPu3tIq4H Content-Type: text/plain; charset=us-ascii Content-Disposition: inline A sequence of two patches is attached. The first fixes the ~2/~4 bug, signalling an error for any unrepresentable offset. The second is a bonus patch, which fixes related problems in ~z, the RFC 822 zone format specifier. Prior to the patch, ~z outputs "Z" for UT, which would be correct for ISO 8601 format but is deprecated (along with all the other single-letter syntax) for RFC 822. The patch changes that to the approved "+0000". ~z also had exactly the same problems as ~2/~4 regarding unrepresentable offsets, so the patch fixes them in the same way. I could report the ~z problems in a separate ticket if you like. Beware that the second of these patches has some textual dependence on the first, so trying to handle them separately might just be confusing. -zefram --4SFOXa2GPu3tIq4H Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-fix-SRFI-19-s-ISO-8601-zone-output-formats.patch" From e6db0e40e5464591df204f9d07e66b3d7853c0d7 Mon Sep 17 00:00:00 2001 From: Zefram <zefram@HIDDEN> Date: Wed, 19 Apr 2017 21:50:39 +0100 Subject: [PATCH 1/2] fix SRFI-19's ISO 8601 zone output formats The ISO 8601 timezone formats offered by SRFI-19's date->string function, in the ~2 and ~4 format specifiers, were erroneously in the basic format despite juxtaposition with extended-format date and time. Fix that by switching them to extended format. This incidentally means that the ISO 8601 zone format is no longer implemented as identical to the RFC 822 zone format (~z), so stop documenting them in terms of ~z. The same format specifiers also made too much of an attempt to display zone offsets that are not representable in ISO 8601 format. They would truncate an offset that is not an integral number of minutes, thus producing inaccurate output. The truncation of an offset in the range (-60, 0) yielded a non-conforming "-0000". An offset of 100 hours or more (in either direction) resulted in non-conforming extra digits. In all of these cases, signal as an error that the zone offset is not representable. --- doc/ref/srfi-modules.texi | 4 ++-- module/srfi/srfi-19.scm | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi index ec3bb20..da7850f 100644 --- a/doc/ref/srfi-modules.texi +++ b/doc/ref/srfi-modules.texi @@ -2818,9 +2818,9 @@ with locale decimal point, eg.@: @samp{5.2} @item @nicode{~z} @tab time zone, RFC-822 style @item @nicode{~Z} @tab time zone symbol (not currently implemented) @item @nicode{~1} @tab ISO-8601 date, @samp{~Y-~m-~d} -@item @nicode{~2} @tab ISO-8601 time+zone, @samp{~H:~M:~S~z} +@item @nicode{~2} @tab ISO-8601 time+zone, @samp{~3} plus zone @item @nicode{~3} @tab ISO-8601 time, @samp{~H:~M:~S} -@item @nicode{~4} @tab ISO-8601 date/time+zone, @samp{~Y-~m-~dT~H:~M:~S~z} +@item @nicode{~4} @tab ISO-8601 date/time+zone, @samp{~5} plus zone @item @nicode{~5} @tab ISO-8601 date/time, @samp{~Y-~m-~dT~H:~M:~S} @end multitable @end defun diff --git a/module/srfi/srfi-19.scm b/module/srfi/srfi-19.scm index f09ec7a..ed88242 100644 --- a/module/srfi/srfi-19.scm +++ b/module/srfi/srfi-19.scm @@ -152,7 +152,6 @@ (define locale-date-time-format "~a ~b ~d ~H:~M:~S~z ~Y") (define locale-short-date-format "~m/~d/~y") (define locale-time-format "~H:~M:~S") -(define iso-8601-date-time-format "~Y-~m-~dT~H:~M:~S~z") ;;-- Miscellaneous Constants. ;;-- only the tai-epoch-in-jd might need changing if @@ -970,6 +969,21 @@ (display (padding hours #\0 2) port) (display (padding minutes #\0 2) port)))) +(define (iso-8601-tz-print offset port) + (let* ((neg? (negative? offset)) + (all-secs (abs offset)) + (seconds (remainder all-secs 60)) + (all-mins (quotient all-secs 60)) + (minutes (remainder all-mins 60)) + (hours (quotient all-mins 60))) + (if (or (not (= seconds 0)) (> hours 99)) + (time-error 'date-printer 'unrepresentable-zone-offset offset) + (begin + (display (if neg? #\- #\+) port) + (display (padding hours #\0 2) port) + (display #\: port) + (display (padding minutes #\0 2) port))))) + ;; A table of output formatting directives. ;; the first time is the format char. ;; the second is a procedure that takes the date, a padding character @@ -1119,11 +1133,13 @@ (cons #\1 (lambda (date pad-with port) (display (date->string date "~Y-~m-~d") port))) (cons #\2 (lambda (date pad-with port) - (display (date->string date "~H:~M:~S~z") port))) + (display (date->string date "~3") port) + (iso-8601-tz-print (date-zone-offset date) port))) (cons #\3 (lambda (date pad-with port) (display (date->string date "~H:~M:~S") port))) (cons #\4 (lambda (date pad-with port) - (display (date->string date "~Y-~m-~dT~H:~M:~S~z") port))) + (display (date->string date "~5") port) + (iso-8601-tz-print (date-zone-offset date) port))) (cons #\5 (lambda (date pad-with port) (display (date->string date "~Y-~m-~dT~H:~M:~S") port))))) -- 2.1.4 --4SFOXa2GPu3tIq4H Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0002-fix-SRFI-19-s-RFC-822-zone-output-format.patch" From 3c78db919ba705a5e3f1b1ac919a473b709d26c6 Mon Sep 17 00:00:00 2001 From: Zefram <zefram@HIDDEN> Date: Wed, 19 Apr 2017 22:06:35 +0100 Subject: [PATCH 2/2] fix SRFI-19's RFC 822 zone output format The RFC 822 timezone format offered by SRFI-19's date->string function, the ~z format specifier, was using the deprecated "Z" format for +0000. Change it to the non-deprecated "+0000". The same format specifier also made too much of an attempt to display zone offsets that are not representable in RFC 822 format. It would truncate an offset that is not an integral number of minutes, thus producing inaccurate output. The truncation of an offset in the range (-60, 0) yielded a non-conforming "-0000". An offset of 100 hours or more (in either direction) resulted in non-conforming extra digits. In all of these cases, signal as an error that the zone offset is not representable. --- module/srfi/srfi-19.scm | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/module/srfi/srfi-19.scm b/module/srfi/srfi-19.scm index ed88242..4b8445f 100644 --- a/module/srfi/srfi-19.scm +++ b/module/srfi/srfi-19.scm @@ -953,21 +953,24 @@ ;; FIXME: mkoeppe: Put a symbolic time zone in the date structs. ;; Print it here instead of the numerical offset if available. (define (locale-print-time-zone date port) - (tz-printer (date-zone-offset date) port)) + (rfc-822-tz-print (date-zone-offset date) port)) (define (locale-am-string/pm hr) (if (> hr 11) (locale-pm-string) (locale-am-string))) -(define (tz-printer offset port) - (cond - ((= offset 0) (display "Z" port)) - ((negative? offset) (display "-" port)) - (else (display "+" port))) - (if (not (= offset 0)) - (let ((hours (abs (quotient offset (* 60 60)))) - (minutes (abs (quotient (remainder offset (* 60 60)) 60)))) +(define (rfc-822-tz-print offset port) + (let* ((neg? (negative? offset)) + (all-secs (abs offset)) + (seconds (remainder all-secs 60)) + (all-mins (quotient all-secs 60)) + (minutes (remainder all-mins 60)) + (hours (quotient all-mins 60))) + (if (or (not (= seconds 0)) (> hours 99)) + (time-error 'date-printer 'unrepresentable-zone-offset offset) + (begin + (display (if neg? #\- #\+) port) (display (padding hours #\0 2) port) - (display (padding minutes #\0 2) port)))) + (display (padding minutes #\0 2) port))))) (define (iso-8601-tz-print offset port) (let* ((neg? (negative? offset)) @@ -1127,7 +1130,7 @@ (cons #\Y (lambda (date pad-with port) (display (date-year date) port))) (cons #\z (lambda (date pad-with port) - (tz-printer (date-zone-offset date) port))) + (rfc-822-tz-print (date-zone-offset date) port))) (cons #\Z (lambda (date pad-with port) (locale-print-time-zone date port))) (cons #\1 (lambda (date pad-with port) -- 2.1.4 --4SFOXa2GPu3tIq4H--
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.