From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Denis 'GNUtoo' Carikli Newsgroups: gmane.lisp.guile.devel Subject: [PATCH v2] SRFI-19: Add support for ISO 8601 zones with a colon. Date: Tue, 19 Mar 2024 21:18:57 +0100 Message-ID: <20240319201857.8687-1-GNUtoo@cyberdimension.org> References: <20240311192508.5b974e64@trisquel64> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15062"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-devel@gnu.org, Denis 'GNUtoo' Carikli To: Rob Browning Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Tue Mar 19 22:51:49 2024 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rmhN6-0003hj-PZ for guile-devel@m.gmane-mx.org; Tue, 19 Mar 2024 22:51:48 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rmhMs-0006Qi-VH; Tue, 19 Mar 2024 17:51:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmhMq-0006QS-Qp for guile-devel@gnu.org; Tue, 19 Mar 2024 17:51:32 -0400 Original-Received: from cyberdimension.org ([80.67.179.20] helo=gnutoo.cyberdimension.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmhMo-0006Ff-6A for guile-devel@gnu.org; Tue, 19 Mar 2024 17:51:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=dkim; bh=pCdwhapcqRv3W4C NQhNU1TkGP/P8iBiCYSxH9O8iixE=; h=references:in-reply-to:date:subject: cc:to:from; d=cyberdimension.org; b=UfQ+Hug+52RcJi130gSNTX4yg3WZggiVps +i4Nfjoj+MFjcEW8gpE8P6eVVO7zv+H3Ba0o4R8m0gtGRtrg4Kt695c3D+p2XfLyvWFaqF 7PgIobitY+sWHoIZhxxQy4OqMPqpThWBT+Vqwta5RcDNUvjKnHM4TTE1iOQbGga9WahFm7 m28K3dNHQqv25ADomTipn1SdDHv9e1PKu73zQsE55C5NDgUz9zu2C2vadR9l1XMXhekDnu k507UTmk7e28p8WvCkrYOmmh84YXXOPPB3a3h8+IH8xQnJgaSNagnFMz4+1rv54YK+5MSd S6xCMayEosATHq6OBt7Zvk/n0/Ew== Original-Received: from localhost.localdomain (localhost [::1]) by gnutoo.cyberdimension.org (OpenSMTPD) with ESMTP id 46348210; Tue, 19 Mar 2024 20:19:38 +0000 (UTC) X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240311192508.5b974e64@trisquel64> Received-SPF: pass client-ip=80.67.179.20; envelope-from=GNUtoo@cyberdimension.org; helo=gnutoo.cyberdimension.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:22353 Archived-At: * 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 --- 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