unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
To: Rob Browning <rlb@defaultvalue.org>
Cc: guile-devel@gnu.org, Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Subject: [PATCH v2] SRFI-19: Add support for ISO 8601 zones with a colon.
Date: Tue, 19 Mar 2024 21:18:57 +0100	[thread overview]
Message-ID: <20240319201857.8687-1-GNUtoo@cyberdimension.org> (raw)
In-Reply-To: <20240311192508.5b974e64@trisquel64>

* module/srfi/srfi-19.scm (zone-reader): handle a colon in the zone.

* test-suite/tests/srfi-19.test (SRFI date/time library test): Add test.

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
---
ChangeLog v1->v2:
- Improved error message to be more meaningful.
- Removed duplicated code: in the v1, the read, oef-object test, and
  error messages were duplicated.
---
 module/srfi/srfi-19.scm       | 16 ++++++++++------
 test-suite/tests/srfi-19.test |  3 +++
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/module/srfi/srfi-19.scm b/module/srfi/srfi-19.scm
index 570f933ca..ad1867506 100644
--- a/module/srfi/srfi-19.scm
+++ b/module/srfi/srfi-19.scm
@@ -1267,12 +1267,16 @@
                               (list "Invalid time zone number" ch)))
               (set! offset (+ offset (* (char->int ch)
                                         60 60))))
-            (let ((ch (read-char port)))
-              (if (eof-object? ch)
-                  (time-error 'string->date 'bad-date-template-string
-                              (list "Invalid time zone number" ch)))
-              (set! offset (+ offset (* (char->int ch)
-                                        10 60))))
+            (let ((f (lambda ()
+                       (let ((ch (read-char port)))
+                         (if (eof-object? ch)
+                             (time-error
+                              'string->date 'bad-date-template-string
+                              (list "Missing required time zone minutes" ch))
+                             ch)))))
+              (let ((ch (f)))
+                (if (char=? ch #\:) (set! ch (f)))
+                (set! offset (+ offset (* (char->int ch) 10 60)))))
             (let ((ch (read-char port)))
               (if (eof-object? ch)
                   (time-error 'string->date 'bad-date-template-string
diff --git a/test-suite/tests/srfi-19.test b/test-suite/tests/srfi-19.test
index 1d56214e4..55eb82320 100644
--- a/test-suite/tests/srfi-19.test
+++ b/test-suite/tests/srfi-19.test
@@ -120,6 +120,9 @@ incomplete numerical tower implementation.)"
   (pass-if "string->date works"
 	   (begin (string->date "2001-06-01@14:00" "~Y-~m-~d@~H:~M")
 		  #t))
+  (pass-if "string->date accepts ISO 8601 zones with a colon"
+	   (begin (string->date "2024-12-31T23:59:59+01:00" "~Y-~m-~dT~H:~M:~S~z")
+		  #t))
   ;; check for code paths where reals were passed to quotient, which
   ;; doesn't work in Guile (and is unspecified in R5RS)
   (test-time->date time-utc->date date->time-utc)

base-commit: 54c4753dd3f7506bee2778b36d7263b613ffd579
-- 
2.41.0




  parent reply	other threads:[~2024-03-19 20:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29 21:23 [PATCH v1] SRFI-19: Add support for ISO 8601 zones with a colon Denis 'GNUtoo' Carikli
2024-03-06 18:42 ` Rob Browning
2024-03-06 18:58   ` Rob Browning
2024-03-11 18:25   ` Denis 'GNUtoo' Carikli
2024-03-19 14:26     ` Denis 'GNUtoo' Carikli
2024-03-19 20:18     ` Denis 'GNUtoo' Carikli [this message]
2024-03-20  0:21     ` Rob Browning
2024-04-05 22:03       ` Rob Browning
2024-04-12 15:19         ` Denis 'GNUtoo' Carikli
2024-04-13 19:44           ` Rob Browning
2024-04-12 15:19       ` Denis 'GNUtoo' Carikli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240319201857.8687-1-GNUtoo@cyberdimension.org \
    --to=gnutoo@cyberdimension.org \
    --cc=guile-devel@gnu.org \
    --cc=rlb@defaultvalue.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).