From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Zefram Newsgroups: gmane.lisp.guile.bugs Subject: bug#21904: date->string duff ISO 8601 format for non-4-digit years Date: Thu, 20 Apr 2017 01:04:37 +0100 Message-ID: <20170420000437.GD912@fysh.org> References: <20151113142229.GO13455@fysh.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="wxDdMuZNg1r63Hyj" X-Trace: blaine.gmane.org 1492646733 11623 195.159.176.226 (20 Apr 2017 00:05:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 20 Apr 2017 00:05:33 +0000 (UTC) To: 21904@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Thu Apr 20 02:05:28 2017 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0zbD-0002qp-B7 for guile-bugs@m.gmane.org; Thu, 20 Apr 2017 02:05:27 +0200 Original-Received: from localhost ([::1]:51014 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0zbG-0005Tv-Ri for guile-bugs@m.gmane.org; Wed, 19 Apr 2017 20:05:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33627) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0zar-0005GE-Ee for bug-guile@gnu.org; Wed, 19 Apr 2017 20:05:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0zao-00059w-9J for bug-guile@gnu.org; Wed, 19 Apr 2017 20:05:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:59444) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d0zao-00059l-21 for bug-guile@gnu.org; Wed, 19 Apr 2017 20:05:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d0zan-0002dt-L9 for bug-guile@gnu.org; Wed, 19 Apr 2017 20:05:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Zefram Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 20 Apr 2017 00:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21904 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 21904-submit@debbugs.gnu.org id=B21904.149264668210129 (code B ref 21904); Thu, 20 Apr 2017 00:05:01 +0000 Original-Received: (at 21904) by debbugs.gnu.org; 20 Apr 2017 00:04:42 +0000 Original-Received: from localhost ([127.0.0.1]:57643 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0zaU-0002dJ-CB for submit@debbugs.gnu.org; Wed, 19 Apr 2017 20:04:42 -0400 Original-Received: from river.fysh.org ([87.98.248.19]:43654 ident=Debian-exim) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0zaS-0002dA-2F for 21904@debbugs.gnu.org; Wed, 19 Apr 2017 20:04:40 -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=OnhXMlbbBpKEqIOyyuu1o+P5n8ntsgZAzfdQJa5Wglo=; b=mZGOSZWUDx60UjJ3JPyo7YnrufV+1h7wO6xTd2LNpCJFdDd5wy4rPB3fzzoIjoEQtnPOmlS/U6AkLhsUoQhQwkC6/tvnFy6V5PLZ9WJ6OG24t5YuRMemJLCSkWMjA1CwgaSDAMUPNN4ca+S/X86BsMb/besrtA3MjrNuZgzgrR4=; Original-Received: from zefram by river.fysh.org with local (Exim 4.84_2 #1 (Debian)) id 1d0zaP-0005jD-Hd; Thu, 20 Apr 2017 01:04:37 +0100 Content-Disposition: inline In-Reply-To: <20151113142229.GO13455@fysh.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:8768 Archived-At: --wxDdMuZNg1r63Hyj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline A patch to fix this is attached. The ISO 8601 date formats were implemented by using the ~Y formatter for the year portion, but SRFI-19 doesn't require ~Y to follow ISO 8601, so this raises the question of whether ~Y should. It could be fixed by changing ~Y to conform to ISO 8601, retaining the existing factoring of the formatters. Or a separate internal formatting function could be instituted to do ISO 8601 year formatting, with ~1 et al using that and ~Y left unchanged. I chose the former strategy, partly because the funny non-linear year number doesn't seem a useful thing to support in date->string at all, but more strongly because it's useful to have access to ISO 8601 year formatting on its own. There isn't any other format specifier for that job; it looks like SRFI-19 imagines that ~Y will fill that need. -zefram --wxDdMuZNg1r63Hyj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-fix-SRFI-19-s-ISO-8601-year-syntax.patch" >From 43dfb5fabc9debb80f87b17d82a1adde356e547c Mon Sep 17 00:00:00 2001 From: Zefram Date: Thu, 20 Apr 2017 00:42:54 +0100 Subject: [PATCH 1/2] fix SRFI-19's ISO 8601 year syntax The ISO 8601 date formats offered by SRFI-19's date->string function were emitting incorrect syntax for most years. At least four digits of year must be given, but it wasn't padding shorter numbers. And any number with more than four digits requires a leading sign, but this was being omitted for positive numbers. These problems are now fixed. The ISO 8601 date formats were formerly implemented in terms of the ~Y format, which was not specified to be an ISO 8601 format. The fix is achieved by altering ~Y to behave in the ISO 8601 manner, and ~Y is now documented to conform to ISO 8601. Doing it this way means that ISO 8601 year numbering is available in isolation, which is a useful facility not otherwise available. --- doc/ref/srfi-modules.texi | 1 + module/srfi/srfi-19.scm | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi index da7850f..8a5f1a0 100644 --- a/doc/ref/srfi-modules.texi +++ b/doc/ref/srfi-modules.texi @@ -2815,6 +2815,7 @@ with locale decimal point, eg.@: @samp{5.2} @item @nicode{~y} @tab year, two digits, @samp{00} to @samp{99} @item @nicode{~Y} @tab year, full, eg.@: @samp{2003} +(in ISO 8601 format, though SRFI-19 doesn't specify so) @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} diff --git a/module/srfi/srfi-19.scm b/module/srfi/srfi-19.scm index 4b8445f..d4308bb 100644 --- a/module/srfi/srfi-19.scm +++ b/module/srfi/srfi-19.scm @@ -1128,7 +1128,10 @@ 2) port))) (cons #\Y (lambda (date pad-with port) - (display (date-year date) port))) + (let ((y (date-year date))) + (cond ((negative? y) (display #\- port)) + ((>= y 10000) (display #\+ port))) + (display (padding (abs y) #\0 4) port)))) (cons #\z (lambda (date pad-with port) (rfc-822-tz-print (date-zone-offset date) port))) (cons #\Z (lambda (date pad-with port) -- 2.1.4 --wxDdMuZNg1r63Hyj--