* Re: [PATCH] Fix for `parse-time-string'
2020-01-24 15:41 ` Lars Ingebrigtsen
@ 2020-01-24 21:45 ` Paul Eggert
2020-01-25 8:43 ` Bastien
0 siblings, 1 reply; 4+ messages in thread
From: Paul Eggert @ 2020-01-24 21:45 UTC (permalink / raw)
To: Lars Ingebrigtsen, Bastien; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 267 bytes --]
On 1/24/20 7:41 AM, Lars Ingebrigtsen wrote:
> Looks good to me.
It looks good to me too. However, it exposes a problem with
iso8601-parse (including one test case failure) that I attempted to fix
by installing the attached patch after installing Bastien's patch.
[-- Attachment #2: 0001-Fix-iso8601-parse-so-unknown-DST-is-1-not-nil.patch --]
[-- Type: text/x-patch, Size: 18294 bytes --]
From a391ffa2f0377306449b36cc62858db823d2e990 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Fri, 24 Jan 2020 13:36:56 -0800
Subject: [PATCH] Fix iso8601-parse so unknown DST is -1, not nil
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The convention in a decoded time’s dst flag is that t means DST,
nil means standard time, and -1 means unknown. This differs from
the convention for other components of a decoded time, where nil
means unknown. Fix some places where iso8601-parse mistakenly
treated nil as meaning that the dst flag was unknown.
* doc/lispref/os.texi (Time Parsing):
Adjust to match parse-time-string’s doc string.
* lisp/calendar/iso8601.el (iso8601-parse):
Set dst flag to nil if a numeric time zone or "Z" is given.
(iso8601--decoded-time): Default dst flag to -1 if no dst
flag or zone is given.
* lisp/calendar/time-date.el (decoded-time-set-defaults):
When we don’t have a time zone, set the dst flag consistently
with DEFAULT-ZONE.
* test/lisp/calendar/iso8601-tests.el (test-iso8601-date-years)
(test-iso8601-date-dates, test-iso8601-date-obsolete)
(test-iso8601-date-weeks, test-iso8601-date-ordinals)
(test-iso8601-time, test-iso8601-combined)
(test-iso8601-duration, test-iso8601-intervals)
(standard-test-dates, standard-test-time-of-day-local-time)
(standard-test-time-of-day-fractions)
(nonstandard-test-time-of-day-decimals)
(standard-test-time-of-day-beginning-of-day)
(standard-test-date-and-time-of-day, standard-test-interval):
Adjust tests to match fixed behavior.
---
doc/lispref/os.texi | 3 +-
lisp/calendar/iso8601.el | 8 +-
lisp/calendar/time-date.el | 17 ++--
test/lisp/calendar/iso8601-tests.el | 142 ++++++++++++++--------------
4 files changed, 87 insertions(+), 83 deletions(-)
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index 201ca18c1e..a034ccdcd5 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -1689,7 +1689,8 @@ Time Parsing
@noindent
The format of this list is the same as what @code{decode-time} accepts
(@pxref{Time Conversion}), and is described in more detail there. Any
-element that cannot be determined from the input will be set to
+@code{dst} element that cannot be determined from the input is set to
+@minus{}1, and any other unknown element is set to
@code{nil}. The argument @var{string} should resemble an RFC 822 (or later) or
ISO 8601 string, like ``Fri, 25 Mar 2016 16:24:56 +0100'' or
``1998-09-12T12:21:54-0200'', but this function will attempt to parse
diff --git a/lisp/calendar/iso8601.el b/lisp/calendar/iso8601.el
index ae1dab1725..e42fe0fa21 100644
--- a/lisp/calendar/iso8601.el
+++ b/lisp/calendar/iso8601.el
@@ -136,7 +136,8 @@ iso8601-parse
(when zone-string
(setf (decoded-time-zone date)
;; The time zone in decoded times are in seconds.
- (* (iso8601-parse-zone zone-string) 60)))
+ (* (iso8601-parse-zone zone-string) 60))
+ (setf (decoded-time-dst date) nil))
date)))
(defun iso8601-parse-date (string)
@@ -332,6 +333,9 @@ iso8601-parse-interval
(list start end
(or duration
;; FIXME: Support subseconds.
+ ;; FIXME: It makes no sense to decode a time difference
+ ;; according to (decoded-time-zone end), or according to
+ ;; any other time zone for that matter.
(decode-time (time-subtract (iso8601--encode-time end)
(iso8601--encode-time start))
(or (decoded-time-zone end) 0) 'integer)))))
@@ -354,7 +358,7 @@ iso8601--decoded-time
(iso8601--value month)
(iso8601--value year)
nil
- dst
+ (if (or dst zone) dst -1)
zone))
(defun iso8601--encode-time (time)
diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el
index 1e589ece29..e2402de801 100644
--- a/lisp/calendar/time-date.el
+++ b/lisp/calendar/time-date.el
@@ -515,15 +515,14 @@ decoded-time-set-defaults
(unless (decoded-time-year time)
(setf (decoded-time-year time) 0))
- ;; When we don't have a time zone and we don't have a DST, then mark
- ;; it as unknown.
- (when (and (not (decoded-time-zone time))
- (not (decoded-time-dst time)))
- (setf (decoded-time-dst time) -1))
-
- (when (and (not (decoded-time-zone time))
- default-zone)
- (setf (decoded-time-zone time) 0))
+ ;; When we don't have a time zone, default to DEFAULT-ZONE without
+ ;; DST if DEFAULT-ZONE if given, and to unknown DST otherwise.
+ (unless (decoded-time-zone time)
+ (if default-zone
+ (progn (setf (decoded-time-zone time) default-zone)
+ (setf (decoded-time-dst time) nil))
+ (setf (decoded-time-dst time) -1)))
+
time)
(provide 'time-date)
diff --git a/test/lisp/calendar/iso8601-tests.el b/test/lisp/calendar/iso8601-tests.el
index 430680c507..6e7a4724a6 100644
--- a/test/lisp/calendar/iso8601-tests.el
+++ b/test/lisp/calendar/iso8601-tests.el
@@ -24,49 +24,49 @@
(ert-deftest test-iso8601-date-years ()
(should (equal (iso8601-parse-date "1985")
- '(nil nil nil nil nil 1985 nil nil nil)))
+ '(nil nil nil nil nil 1985 nil -1 nil)))
(should (equal (iso8601-parse-date "-0003")
- '(nil nil nil nil nil -3 nil nil nil)))
+ '(nil nil nil nil nil -3 nil -1 nil)))
(should (equal (iso8601-parse-date "+1985")
- '(nil nil nil nil nil 1985 nil nil nil))))
+ '(nil nil nil nil nil 1985 nil -1 nil))))
(ert-deftest test-iso8601-date-dates ()
(should (equal (iso8601-parse-date "1985-03-14")
- '(nil nil nil 14 3 1985 nil nil nil)))
+ '(nil nil nil 14 3 1985 nil -1 nil)))
(should (equal (iso8601-parse-date "19850314")
- '(nil nil nil 14 3 1985 nil nil nil)))
+ '(nil nil nil 14 3 1985 nil -1 nil)))
(should (equal (iso8601-parse-date "1985-02")
- '(nil nil nil nil 2 1985 nil nil nil))))
+ '(nil nil nil nil 2 1985 nil -1 nil))))
(ert-deftest test-iso8601-date-obsolete ()
(should (equal (iso8601-parse-date "--02-01")
- '(nil nil nil 1 2 nil nil nil nil)))
+ '(nil nil nil 1 2 nil nil -1 nil)))
(should (equal (iso8601-parse-date "--0201")
- '(nil nil nil 1 2 nil nil nil nil))))
+ '(nil nil nil 1 2 nil nil -1 nil))))
(ert-deftest test-iso8601-date-weeks ()
(should (equal (iso8601-parse-date "2008W39-6")
- '(nil nil nil 27 9 2008 nil nil nil)))
+ '(nil nil nil 27 9 2008 nil -1 nil)))
(should (equal (iso8601-parse-date "2009W01-1")
- '(nil nil nil 29 12 2008 nil nil nil)))
+ '(nil nil nil 29 12 2008 nil -1 nil)))
(should (equal (iso8601-parse-date "2009W53-7")
- '(nil nil nil 3 1 2010 nil nil nil))))
+ '(nil nil nil 3 1 2010 nil -1 nil))))
(ert-deftest test-iso8601-date-ordinals ()
(should (equal (iso8601-parse-date "1981-095")
- '(nil nil nil 5 4 1981 nil nil nil))))
+ '(nil nil nil 5 4 1981 nil -1 nil))))
(ert-deftest test-iso8601-time ()
(should (equal (iso8601-parse-time "13:47:30")
- '(30 47 13 nil nil nil nil nil nil)))
+ '(30 47 13 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "134730")
- '(30 47 13 nil nil nil nil nil nil)))
+ '(30 47 13 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "1347")
- '(0 47 13 nil nil nil nil nil nil))))
+ '(0 47 13 nil nil nil nil -1 nil))))
(ert-deftest test-iso8601-combined ()
(should (equal (iso8601-parse "2008-03-02T13:47:30")
- '(30 47 13 2 3 2008 nil nil nil)))
+ '(30 47 13 2 3 2008 nil -1 nil)))
(should (equal (iso8601-parse "2008-03-02T13:47:30Z")
'(30 47 13 2 3 2008 nil nil 0)))
(should (equal (iso8601-parse "2008-03-02T13:47:30+01:00")
@@ -76,13 +76,13 @@ test-iso8601-combined
(ert-deftest test-iso8601-duration ()
(should (equal (iso8601-parse-duration "P3Y6M4DT12H30M5S")
- '(5 30 12 4 6 3 nil nil nil)))
+ '(5 30 12 4 6 3 nil -1 nil)))
(should (equal (iso8601-parse-duration "P1M")
- '(0 0 0 0 1 0 nil nil nil)))
+ '(0 0 0 0 1 0 nil -1 nil)))
(should (equal (iso8601-parse-duration "PT1M")
- '(0 1 0 0 0 0 nil nil nil)))
+ '(0 1 0 0 0 0 nil -1 nil)))
(should (equal (iso8601-parse-duration "P0003-06-04T12:30:05")
- '(5 30 12 4 6 3 nil nil nil))))
+ '(5 30 12 4 6 3 nil -1 nil))))
(ert-deftest test-iso8601-invalid ()
(should-not (iso8601-valid-p " 2008-03-02T13:47:30-01"))
@@ -101,88 +101,88 @@ test-iso8601-intervals
(should (equal (iso8601-parse-interval "2007-03-01T13:00:00Z/P1Y2M10DT2H30M")
'((0 0 13 1 3 2007 nil nil 0)
(0 30 15 11 5 2008 nil nil 0)
- (0 30 2 10 2 1 nil nil nil))))
+ (0 30 2 10 2 1 nil -1 nil))))
(should (equal (iso8601-parse-interval "P1Y2M10DT2H30M/2008-05-11T15:30:00Z")
'((0 0 13 1 3 2007 nil nil 0)
(0 30 15 11 5 2008 nil nil 0)
- (0 30 2 10 2 1 nil nil nil)))))
+ (0 30 2 10 2 1 nil -1 nil)))))
(ert-deftest standard-test-dates ()
(should (equal (iso8601-parse-date "19850412")
- '(nil nil nil 12 4 1985 nil nil nil)))
+ '(nil nil nil 12 4 1985 nil -1 nil)))
(should (equal (iso8601-parse-date "1985-04-12")
- '(nil nil nil 12 4 1985 nil nil nil)))
+ '(nil nil nil 12 4 1985 nil -1 nil)))
(should (equal (iso8601-parse-date "1985102")
- '(nil nil nil 12 4 1985 nil nil nil)))
+ '(nil nil nil 12 4 1985 nil -1 nil)))
(should (equal (iso8601-parse-date "1985-102")
- '(nil nil nil 12 4 1985 nil nil nil)))
+ '(nil nil nil 12 4 1985 nil -1 nil)))
(should (equal (iso8601-parse-date "1985W155")
- '(nil nil nil 12 4 1985 nil nil nil)))
+ '(nil nil nil 12 4 1985 nil -1 nil)))
(should (equal (iso8601-parse-date "1985-W15-5")
- '(nil nil nil 12 4 1985 nil nil nil)))
+ '(nil nil nil 12 4 1985 nil -1 nil)))
(should (equal (iso8601-parse-date "1985W15")
- '(nil nil nil 7 4 1985 nil nil nil)))
+ '(nil nil nil 7 4 1985 nil -1 nil)))
(should (equal (iso8601-parse-date "1985-W15")
- '(nil nil nil 7 4 1985 nil nil nil)))
+ '(nil nil nil 7 4 1985 nil -1 nil)))
(should (equal (iso8601-parse-date "1985-04")
- '(nil nil nil nil 4 1985 nil nil nil)))
+ '(nil nil nil nil 4 1985 nil -1 nil)))
(should (equal (iso8601-parse-date "1985")
- '(nil nil nil nil nil 1985 nil nil nil)))
+ '(nil nil nil nil nil 1985 nil -1 nil)))
(should (equal (iso8601-parse-date "+1985-04-12")
- '(nil nil nil 12 4 1985 nil nil nil)))
+ '(nil nil nil 12 4 1985 nil -1 nil)))
(should (equal (iso8601-parse-date "+19850412")
- '(nil nil nil 12 4 1985 nil nil nil))))
+ '(nil nil nil 12 4 1985 nil -1 nil))))
(ert-deftest standard-test-time-of-day-local-time ()
(should (equal (iso8601-parse-time "152746")
- '(46 27 15 nil nil nil nil nil nil)))
+ '(46 27 15 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "15:27:46")
- '(46 27 15 nil nil nil nil nil nil)))
+ '(46 27 15 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "1528")
- '(0 28 15 nil nil nil nil nil nil)))
+ '(0 28 15 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "15:28")
- '(0 28 15 nil nil nil nil nil nil)))
+ '(0 28 15 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "15")
- '(0 0 15 nil nil nil nil nil nil))))
+ '(0 0 15 nil nil nil nil -1 nil))))
(ert-deftest standard-test-time-of-day-fractions ()
(should (equal (iso8601-parse-time "152735,5" t)
- '((355 . 10) 27 15 nil nil nil nil nil nil)))
+ '((355 . 10) 27 15 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "15:27:35,5" t)
- '((355 . 10) 27 15 nil nil nil nil nil nil)))
+ '((355 . 10) 27 15 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "2320,5" t)
- '(30 20 23 nil nil nil nil nil nil)))
+ '(30 20 23 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "23:20,8" t)
- '(48 20 23 nil nil nil nil nil nil)))
+ '(48 20 23 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "23,3" t)
- '(0 18 23 nil nil nil nil nil nil))))
+ '(0 18 23 nil nil nil nil -1 nil))))
(ert-deftest nonstandard-test-time-of-day-decimals ()
(should (equal (iso8601-parse-time "15:27:35.123" t)
- '((35123 . 1000) 27 15 nil nil nil nil nil nil)))
+ '((35123 . 1000) 27 15 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "15:27:35.123456789" t)
- '((35123456789 . 1000000000) 27 15 nil nil nil nil nil nil))))
+ '((35123456789 . 1000000000) 27 15 nil nil nil nil -1 nil))))
(ert-deftest standard-test-time-of-day-beginning-of-day ()
(should (equal (iso8601-parse-time "000000")
- '(0 0 0 nil nil nil nil nil nil)))
+ '(0 0 0 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "00:00:00")
- '(0 0 0 nil nil nil nil nil nil)))
+ '(0 0 0 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "0000")
- '(0 0 0 nil nil nil nil nil nil)))
+ '(0 0 0 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "00:00")
- '(0 0 0 nil nil nil nil nil nil))))
+ '(0 0 0 nil nil nil nil -1 nil))))
(ert-deftest standard-test-time-of-day-utc ()
(should (equal (iso8601-parse-time "232030Z")
@@ -222,9 +222,9 @@ standard-test-time-of-day-zone
(ert-deftest standard-test-date-and-time-of-day ()
(should (equal (iso8601-parse "19850412T101530")
- '(30 15 10 12 4 1985 nil nil nil)))
+ '(30 15 10 12 4 1985 nil -1 nil)))
(should (equal (iso8601-parse "1985-04-12T10:15:30")
- '(30 15 10 12 4 1985 nil nil nil)))
+ '(30 15 10 12 4 1985 nil -1 nil)))
(should (equal (iso8601-parse "1985102T235030Z")
'(30 50 23 12 4 1985 nil nil 0)))
@@ -232,9 +232,9 @@ standard-test-date-and-time-of-day
'(30 50 23 12 4 1985 nil nil 0)))
(should (equal (iso8601-parse "1985W155T235030")
- '(30 50 23 12 4 1985 nil nil nil)))
+ '(30 50 23 12 4 1985 nil -1 nil)))
(should (equal (iso8601-parse "1985-W155T23:50:30")
- '(30 50 23 12 4 1985 nil nil nil))))
+ '(30 50 23 12 4 1985 nil -1 nil))))
(ert-deftest standard-test-interval ()
;; A time interval starting at 20 minutes and 50 seconds past 23
@@ -256,48 +256,48 @@ standard-test-interval
;; This example doesn't seem valid according to the standard.
;; "0625" is unambiguous, and means "the year 625". Weird.
;; (should (equal (iso8601-parse-interval "19850412/0625")
- ;; '((nil nil nil 12 4 1985 nil nil nil)
- ;; (nil nil nil nil nil 625 nil nil nil)
+ ;; '((nil nil nil 12 4 1985 nil -1 nil)
+ ;; (nil nil nil nil nil 625 nil -1 nil)
;; (0 17 0 22 9 609 5 nil 0))))
;; A time interval of 2 years, 10 months, 15 days, 10 hours, 20
;; minutes and 30 seconds.
(should (equal (iso8601-parse-duration "P2Y10M15DT10H20M30S")
- '(30 20 10 15 10 2 nil nil nil)))
+ '(30 20 10 15 10 2 nil -1 nil)))
(should (equal (iso8601-parse-duration "P00021015T102030")
- '(30 20 10 15 10 2 nil nil nil)))
+ '(30 20 10 15 10 2 nil -1 nil)))
(should (equal (iso8601-parse-duration "P0002-10-15T10:20:30")
- '(30 20 10 15 10 2 nil nil nil)))
+ '(30 20 10 15 10 2 nil -1 nil)))
;; A time interval of 1 year and 6 months.
(should (equal (iso8601-parse-duration "P1Y6M")
- '(0 0 0 0 6 1 nil nil nil)))
+ '(0 0 0 0 6 1 nil -1 nil)))
(should (equal (iso8601-parse-duration "P0001-06")
- '(nil nil nil nil 6 1 nil nil nil)))
+ '(nil nil nil nil 6 1 nil -1 nil)))
;; A time interval of seventy-two hours.
(should (equal (iso8601-parse-duration "PT72H")
- '(0 0 72 0 0 0 nil nil nil)))
+ '(0 0 72 0 0 0 nil -1 nil)))
;; Defined by start and duration
;; A time interval of 1 year, 2 months, 15 days and 12 hours,
;; beginning on 12 April 1985 at 20 minutes past 23 hours.
(should (equal (iso8601-parse-interval "19850412T232000/P1Y2M15DT12H")
- '((0 20 23 12 4 1985 nil nil nil)
- (0 20 11 28 6 1986 nil nil nil)
- (0 0 12 15 2 1 nil nil nil))))
+ '((0 20 23 12 4 1985 nil -1 nil)
+ (0 20 11 28 6 1986 nil -1 nil)
+ (0 0 12 15 2 1 nil -1 nil))))
(should (equal (iso8601-parse-interval "1985-04-12T23:20:00/P1Y2M15DT12H")
- '((0 20 23 12 4 1985 nil nil nil)
- (0 20 11 28 6 1986 nil nil nil)
- (0 0 12 15 2 1 nil nil nil))))
+ '((0 20 23 12 4 1985 nil -1 nil)
+ (0 20 11 28 6 1986 nil -1 nil)
+ (0 0 12 15 2 1 nil -1 nil))))
;; Defined by duration and end
;; A time interval of 1 year, 2 months, 15 days and 12 hours, ending
;; on 12 April 1985 at 20 minutes past 23 hour.
(should (equal (iso8601-parse-interval "P1Y2M15DT12H/19850412T232000")
- '((0 20 11 28 1 1984 nil nil nil)
- (0 20 23 12 4 1985 nil nil nil)
- (0 0 12 15 2 1 nil nil nil)))))
+ '((0 20 11 28 1 1984 nil -1 nil)
+ (0 20 23 12 4 1985 nil -1 nil)
+ (0 0 12 15 2 1 nil -1 nil)))))
;;; iso8601-tests.el ends here
--
2.24.1
^ permalink raw reply related [flat|nested] 4+ messages in thread