aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2018-09-21 14:24:42 -0700
committerPaul Eggert2018-09-21 14:25:19 -0700
commit0bec064454adac2bdff04a11bbdfaa79aa4ce052 (patch)
treeab85b4e46d2ab44dd3d02b85a5a540470842e470
parent167274d44f1ccaee65a5b68e15c3ed79a53447d1 (diff)
downloademacs-0bec064454adac2bdff04a11bbdfaa79aa4ce052.tar.gz
emacs-0bec064454adac2bdff04a11bbdfaa79aa4ce052.zip
Fix ambiguity in nil DST flag
Formerly nil meant both that DST was not in effect and that the DST flag was unknown, and different functions interpreted the flag differently. Now the meaning is consistently nil for DST not in effect, and -1 for DST flag not known. * doc/lispref/os.texi (Time Conversion): The DST slot is now three-valued, not two-. * doc/misc/emacs-mime.texi (time-date): Adjust to new behavior. * etc/NEWS: Mention this. * lisp/calendar/parse-time.el (parse-time-string): * src/editfns.c (Fdecode_time): Return -1 for unknown DST flag. * test/lisp/calendar/parse-time-tests.el (parse-time-tests): Adjust tests to match new behavior, and add a new test for nil vs -1.
-rw-r--r--doc/lispref/os.texi3
-rw-r--r--doc/misc/emacs-mime.texi2
-rw-r--r--etc/NEWS8
-rw-r--r--lisp/calendar/parse-time.el10
-rw-r--r--src/editfns.c6
-rw-r--r--test/lisp/calendar/parse-time-tests.el20
6 files changed, 32 insertions, 17 deletions
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index 0b9dd1c9cc3..43ca9ede00b 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -1423,7 +1423,8 @@ The year, an integer typically greater than 1900.
1423The day of week, as an integer between 0 and 6, where 0 stands for 1423The day of week, as an integer between 0 and 6, where 0 stands for
1424Sunday. 1424Sunday.
1425@item dst 1425@item dst
1426@code{t} if daylight saving time is effect, otherwise @code{nil}. 1426@code{t} if daylight saving time is effect, @code{nil} if it is not
1427in effect, and @minus{}1 if this information is not available.
1427@item utcoff 1428@item utcoff
1428An integer indicating the Universal Time offset in seconds, i.e., the number of 1429An integer indicating the Universal Time offset in seconds, i.e., the number of
1429seconds east of Greenwich. 1430seconds east of Greenwich.
diff --git a/doc/misc/emacs-mime.texi b/doc/misc/emacs-mime.texi
index b71cc3755bf..45f37fb8557 100644
--- a/doc/misc/emacs-mime.texi
+++ b/doc/misc/emacs-mime.texi
@@ -1535,7 +1535,7 @@ Here's a bunch of time/date/second/day examples:
1535 1535
1536@example 1536@example
1537(parse-time-string "Sat Sep 12 12:21:54 1998 +0200") 1537(parse-time-string "Sat Sep 12 12:21:54 1998 +0200")
1538@result{} (54 21 12 12 9 1998 6 nil 7200) 1538@result{} (54 21 12 12 9 1998 6 -1 7200)
1539 1539
1540(date-to-time "Sat Sep 12 12:21:54 1998 +0200") 1540(date-to-time "Sat Sep 12 12:21:54 1998 +0200")
1541@result{} (13818 19266) 1541@result{} (13818 19266)
diff --git a/etc/NEWS b/etc/NEWS
index 736955be0cb..2158fdc10dd 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1060,6 +1060,14 @@ a multibyte string even if its second argument is an ASCII character.
1060** (format "%d" X) no longer mishandles a floating-point number X that 1060** (format "%d" X) no longer mishandles a floating-point number X that
1061does not fit in a machine integer. 1061does not fit in a machine integer.
1062 1062
1063+++
1064** In the DST slot, encode-time and parse-time-string now return -1
1065if it is not known whether daylight saving time is in effect.
1066Formerly they were inconsistent: encode-time returned t in this
1067situation, whereas parse-time-string returned nil. Now they
1068consistently use use nil to mean that DST is not in effect, and use -1
1069to mean that it is not known whether DST is in effect.
1070
1063** New JSON parsing and serialization functions 'json-serialize', 1071** New JSON parsing and serialization functions 'json-serialize',
1064'json-insert', 'json-parse-string', and 'json-parse-buffer'. These 1072'json-insert', 'json-parse-string', and 'json-parse-buffer'. These
1065are implemented in C using the Jansson library. 1073are implemented in C using the Jansson library.
diff --git a/lisp/calendar/parse-time.el b/lisp/calendar/parse-time.el
index 2f9e557dabc..d6c1e9ea169 100644
--- a/lisp/calendar/parse-time.el
+++ b/lisp/calendar/parse-time.el
@@ -29,8 +29,9 @@
29 29
30;; `parse-time-string' parses a time in a string and returns a list of 9 30;; `parse-time-string' parses a time in a string and returns a list of 9
31;; values, just like `decode-time', where unspecified elements in the 31;; values, just like `decode-time', where unspecified elements in the
32;; string are returned as nil. `encode-time' may be applied on these 32;; string are returned as nil (except unspecfied DST is returned as -1).
33;; values to obtain an internal time value. 33;; `encode-time' may be applied on these values to obtain an internal
34;; time value.
34 35
35;;; Code: 36;;; Code:
36 37
@@ -151,8 +152,9 @@ STRING should be on something resembling an RFC2822 string, a la
151somewhat liberal in what format it accepts, and will attempt to 152somewhat liberal in what format it accepts, and will attempt to
152return a \"likely\" value even for somewhat malformed strings. 153return a \"likely\" value even for somewhat malformed strings.
153The values returned are identical to those of `decode-time', but 154The values returned are identical to those of `decode-time', but
154any values that are unknown are returned as nil." 155any unknown values other than DST are returned as nil, and an
155 (let ((time (list nil nil nil nil nil nil nil nil nil)) 156unknown DST value is returned as -1."
157 (let ((time (list nil nil nil nil nil nil nil -1 nil))
156 (temp (parse-time-tokenize (downcase string)))) 158 (temp (parse-time-tokenize (downcase string))))
157 (while temp 159 (while temp
158 (let ((parse-time-elt (pop temp)) 160 (let ((parse-time-elt (pop temp))
diff --git a/src/editfns.c b/src/editfns.c
index 8c7491beedc..047a73f0b8c 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2165,7 +2165,8 @@ between 0 and 23. DAY is an integer between 1 and 31. MONTH is an
2165integer between 1 and 12. YEAR is an integer indicating the 2165integer between 1 and 12. YEAR is an integer indicating the
2166four-digit year. DOW is the day of week, an integer between 0 and 6, 2166four-digit year. DOW is the day of week, an integer between 0 and 6,
2167where 0 is Sunday. DST is t if daylight saving time is in effect, 2167where 0 is Sunday. DST is t if daylight saving time is in effect,
2168otherwise nil. UTCOFF is an integer indicating the UTC offset in 2168nil if it is not in effect, and -1 if this information is
2169not available. UTCOFF is an integer indicating the UTC offset in
2169seconds, i.e., the number of seconds east of Greenwich. (Note that 2170seconds, i.e., the number of seconds east of Greenwich. (Note that
2170Common Lisp has different meanings for DOW and UTCOFF.) 2171Common Lisp has different meanings for DOW and UTCOFF.)
2171 2172
@@ -2194,7 +2195,8 @@ usage: (decode-time &optional TIME ZONE) */)
2194 make_fixnum (local_tm.tm_mon + 1), 2195 make_fixnum (local_tm.tm_mon + 1),
2195 make_fixnum (local_tm.tm_year + tm_year_base), 2196 make_fixnum (local_tm.tm_year + tm_year_base),
2196 make_fixnum (local_tm.tm_wday), 2197 make_fixnum (local_tm.tm_wday),
2197 local_tm.tm_isdst ? Qt : Qnil, 2198 (local_tm.tm_isdst < 0 ? make_fixnum (-1)
2199 : local_tm.tm_isdst == 0 ? Qnil : Qt),
2198 (HAVE_TM_GMTOFF 2200 (HAVE_TM_GMTOFF
2199 ? make_fixnum (tm_gmtoff (&local_tm)) 2201 ? make_fixnum (tm_gmtoff (&local_tm))
2200 : gmtime_r (&time_spec, &gmt_tm) 2202 : gmtime_r (&time_spec, &gmt_tm)
diff --git a/test/lisp/calendar/parse-time-tests.el b/test/lisp/calendar/parse-time-tests.el
index 3a956a56621..9689997f793 100644
--- a/test/lisp/calendar/parse-time-tests.el
+++ b/test/lisp/calendar/parse-time-tests.el
@@ -28,21 +28,23 @@
28 28
29(ert-deftest parse-time-tests () 29(ert-deftest parse-time-tests ()
30 (should (equal (parse-time-string "Mon, 22 Feb 2016 19:35:42 +0100") 30 (should (equal (parse-time-string "Mon, 22 Feb 2016 19:35:42 +0100")
31 '(42 35 19 22 2 2016 1 nil 3600))) 31 '(42 35 19 22 2 2016 1 -1 3600)))
32 (should (equal (parse-time-string "22 Feb 2016 19:35:42 +0100") 32 (should (equal (parse-time-string "22 Feb 2016 19:35:42 +0100")
33 '(42 35 19 22 2 2016 nil nil 3600))) 33 '(42 35 19 22 2 2016 nil -1 3600)))
34 (should (equal (parse-time-string "22 Feb 2016 +0100") 34 (should (equal (parse-time-string "22 Feb 2016 +0100")
35 '(nil nil nil 22 2 2016 nil nil 3600))) 35 '(nil nil nil 22 2 2016 nil -1 3600)))
36 (should (equal (parse-time-string "Mon, 22 Feb 16 19:35:42 +0100") 36 (should (equal (parse-time-string "Mon, 22 Feb 16 19:35:42 +0100")
37 '(42 35 19 22 2 2016 1 nil 3600))) 37 '(42 35 19 22 2 2016 1 -1 3600)))
38 (should (equal (parse-time-string "Mon, 22 February 2016 19:35:42 +0100") 38 (should (equal (parse-time-string "Mon, 22 February 2016 19:35:42 +0100")
39 '(42 35 19 22 2 2016 1 nil 3600))) 39 '(42 35 19 22 2 2016 1 -1 3600)))
40 (should (equal (parse-time-string "Mon, 22 feb 2016 19:35:42 +0100") 40 (should (equal (parse-time-string "Mon, 22 feb 2016 19:35:42 +0100")
41 '(42 35 19 22 2 2016 1 nil 3600))) 41 '(42 35 19 22 2 2016 1 -1 3600)))
42 (should (equal (parse-time-string "Monday, 22 february 2016 19:35:42 +0100") 42 (should (equal (parse-time-string "Monday, 22 february 2016 19:35:42 +0100")
43 '(42 35 19 22 2 2016 1 nil 3600))) 43 '(42 35 19 22 2 2016 1 -1 3600)))
44 (should (equal (parse-time-string "Monday, 22 february 2016 19:35:42 PDT") 44 (should (equal (parse-time-string "Monday, 22 february 2016 19:35:42 PST")
45 '(42 35 19 22 2 2016 1 t -25200))) 45 '(42 35 19 22 2 2016 1 nil -28800)))
46 (should (equal (parse-time-string "Friday, 21 Sep 2018 13:47:58 PDT")
47 '(58 47 13 21 9 2018 5 t -25200)))
46 (should (equal (parse-iso8601-time-string "1998-09-12T12:21:54-0200") 48 (should (equal (parse-iso8601-time-string "1998-09-12T12:21:54-0200")
47 '(13818 33666))) 49 '(13818 33666)))
48 (should (equal (parse-iso8601-time-string "1998-09-12T12:21:54-0230") 50 (should (equal (parse-iso8601-time-string "1998-09-12T12:21:54-0230")