unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#26261: ~N mishandles small nanoseconds value
@ 2017-03-26  2:19 Zefram
  2017-03-27 16:06 ` Andrew Moss
  0 siblings, 1 reply; 3+ messages in thread
From: Zefram @ 2017-03-26  2:19 UTC (permalink / raw)
  To: 26261

The ~N format specifier in SRFI-19's date->string is documented to show
the nanoseconds value, with zero padding.  The documentation explicates
further by showing as an example a string of nine zeroes.  In fact the
implementation only pads to seven digits, and so produces incorrect
output for and nanoseconds value in the range [0, 100000000):

scheme@(guile-user)> (use-modules (srfi srfi-19))
scheme@(guile-user)> (date->string (make-date 0 5 34 12 26 3 2017 0) "~N")
$1 = "0000000"
scheme@(guile-user)> (date->string (make-date 2 5 34 12 26 3 2017 0) "~N")
$2 = "0000002"
scheme@(guile-user)> (date->string (make-date 200 5 34 12 26 3 2017 0) "~N")
$3 = "0000200"
scheme@(guile-user)> (date->string (make-date 200000 5 34 12 26 3 2017 0) "~N")
$4 = "0200000"
scheme@(guile-user)> (date->string (make-date 99999999 5 34 12 26 3 2017 0) "~N")
$5 = "99999999"
scheme@(guile-user)> (date->string (make-date 200000000 5 34 12 26 3 2017 0) "~N")
$6 = "200000000"

The padding clearly has to be to the full nine digits.

-zefram





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#26261: ~N mishandles small nanoseconds value
  2017-03-26  2:19 bug#26261: ~N mishandles small nanoseconds value Zefram
@ 2017-03-27 16:06 ` Andrew Moss
  2017-04-19 13:14   ` Andy Wingo
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Moss @ 2017-03-27 16:06 UTC (permalink / raw)
  To: 26261


[-- Attachment #1.1: Type: text/plain, Size: 140 bytes --]

I believe I have fixed this bug, but I'm not sure if I put the test case in
the right place within the file. Please see the attached patch.

[-- Attachment #1.2: Type: text/html, Size: 180 bytes --]

[-- Attachment #2: 0001-Fixed-bug-N-mishandles-small-nanoseconds-value.patch --]
[-- Type: text/x-patch, Size: 1802 bytes --]

From e975f8ae8d494985a51faed5b15c5664a557e0e2 Mon Sep 17 00:00:00 2001
From: Andrew Moss <andrewmoss@pobox.com>
Date: Mon, 27 Mar 2017 11:58:29 -0400
Subject: [PATCH] Fixed bug: ~N mishandles small nanoseconds value

Fixes <http://bugs.gnu.org/26261>.
Reported by Zefram <zefram@fysh.org>.

* module/srfi/srfi-19.scm ("define directives"): N padding increased from 7 to 9

* test-suite/tests/srfi-19.test ("date->string"): New test.
---
 module/srfi/srfi-19.scm       | 2 +-
 test-suite/tests/srfi-19.test | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/module/srfi/srfi-19.scm b/module/srfi/srfi-19.scm
index 658ccd9..4823f2f 100644
--- a/module/srfi/srfi-19.scm
+++ b/module/srfi/srfi-19.scm
@@ -1060,7 +1060,7 @@
                (newline port)))
    (cons #\N (lambda (date pad-with port)
                (display (padding (date-nanosecond date)
-                                      pad-with 7)
+                                      pad-with 9)
                         port)))
    (cons #\p (lambda (date pad-with port)
                (display (locale-am-string/pm (date-hour date)) port)))
diff --git a/test-suite/tests/srfi-19.test b/test-suite/tests/srfi-19.test
index d63e622..534cd7c 100644
--- a/test-suite/tests/srfi-19.test
+++ b/test-suite/tests/srfi-19.test
@@ -175,6 +175,11 @@ incomplete numerical tower implementation.)"
       (equal? "Sun Jun 05 18:33:00+0200 2005"
               (date->string date))))
 
+  (pass-if "date->string pads small nanoseconds values correctly"
+    (let* ((date (make-date 99999999 5 34 12 26 3 2017 0)))
+      (equal? "099999999"
+              (date->string date "~N"))))
+
   ;; check time comparison procedures
   (let* ((time1 (make-time time-monotonic 0 0))
          (time2 (make-time time-monotonic 0 0))
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#26261: ~N mishandles small nanoseconds value
  2017-03-27 16:06 ` Andrew Moss
@ 2017-04-19 13:14   ` Andy Wingo
  0 siblings, 0 replies; 3+ messages in thread
From: Andy Wingo @ 2017-04-19 13:14 UTC (permalink / raw)
  To: Andrew Moss; +Cc: 26261-done

On Mon 27 Mar 2017 18:06, Andrew Moss <andrewmoss@pobox.com> writes:

> I believe I have fixed this bug, but I'm not sure if I put the test
> case in the right place within the file. Please see the attached
> patch.
>
> From e975f8ae8d494985a51faed5b15c5664a557e0e2 Mon Sep 17 00:00:00 2001
> From: Andrew Moss <andrewmoss@pobox.com>
> Date: Mon, 27 Mar 2017 11:58:29 -0400
> Subject: [PATCH] Fixed bug: ~N mishandles small nanoseconds value
>
> Fixes <http://bugs.gnu.org/26261>.
> Reported by Zefram <zefram@fysh.org>.
>
> * module/srfi/srfi-19.scm ("define directives"): N padding increased from 7 to 9
>
> * test-suite/tests/srfi-19.test ("date->string"): New test.

Applied.  Thank you very very much for the fix!

Andy





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-19 13:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-26  2:19 bug#26261: ~N mishandles small nanoseconds value Zefram
2017-03-27 16:06 ` Andrew Moss
2017-04-19 13:14   ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).