]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix icalendar time zone parsing
authordickmao <dick.r.chiang@gmail.com>
Sun, 21 Nov 2021 08:18:57 +0000 (09:18 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 21 Nov 2021 08:20:06 +0000 (09:20 +0100)
* lisp/calendar/icalendar.el (icalendar--decode-isodatetime):
Parse time zones more correctly.
* test/lisp/calendar/icalendar-tests.el
(icalendar-tests--decode-isodatetime): Fix tests so that they work
in other time zones than Europe/Berlin (bug#51959).

lisp/calendar/icalendar.el
test/lisp/calendar/icalendar-tests.el

index 2d31101e50e5e40c4388ac7242fbf98d428b26e9..7a483d40627148ec43f720e8890dc393525a18cb 100644 (file)
@@ -644,13 +644,13 @@ FIXME: multiple comma-separated values should be allowed!"
           ;; seconds present
           (setq second (read (substring isodatetimestring 13 15))))
        ;; FIXME: Support subseconds.
-        (when (and (> (length isodatetimestring) 15)
-                   ;; UTC specifier present
-                   (char-equal ?Z (aref isodatetimestring 15)))
-          (setq source-zone t
-                ;; decode to local time unless result-zone is explicitly given,
-                ;; i.e. do not decode to UTC, i.e. do not (setq result-zone t)
-                ))
+        (when (> (length isodatetimestring) 15)
+          (cl-case (aref isodatetimestring 15)
+            (?Z
+             (setq source-zone t))
+            ((?- ?+)
+             (setq source-zone
+                   (concat "UTC" (substring isodatetimestring 15))))))
         ;; shift if necessary
         (if day-shift
             (let ((mdy (calendar-gregorian-from-absolute
index 10b684aacbebd98365aad2d857ff18379c744f99..1551922028c52d41f43a3d219fc4371944950a8a 100644 (file)
@@ -1635,26 +1635,30 @@ SUMMARY:NNN Wwwwwwww Wwwww - Aaaaaa Pppppppp rrrrrr ddd oo Nnnnnnnn 30
 
 (ert-deftest icalendar-tests--decode-isodatetime ()
   "Test `icalendar--decode-isodatetime'."
-  (should (equal (icalendar-test--format "20040917T050910-0200")
-                 "2004-09-17T03:09:10+0000"))
-  (should (equal (icalendar-test--format "20040917T050910")
+  (should (equal (icalendar-test--format "20040917T050910-02:00")
                  "2004-09-17T03:09:10+0000"))
+  (let ((orig (icalendar-test--format "20040917T050910")))
+    (unwind-protect
+        (progn
+          (set-time-zone-rule "UTC-02:00")
+          (should (equal (icalendar-test--format "20040917T050910")
+                         "2004-09-17T03:09:10+0000"))
+          (should (equal (icalendar-test--format "20040917T0509")
+                         "2004-09-17T03:09:00+0000"))
+          (should (equal (icalendar-test--format "20040917")
+                         "2004-09-16T22:00:00+0000"))
+          (should (equal (icalendar-test--format "20040917T050910" 1)
+                         "2004-09-18T03:09:10+0000"))
+          (should (equal (icalendar-test--format "20040917T050910" 30)
+                         "2004-10-17T03:09:10+0000")))
+      (set-time-zone-rule 'wall) ;; (set-time-zone-rule nil) is broken
+      (should (equal orig (icalendar-test--format "20040917T050910")))))
   (should (equal (icalendar-test--format "20040917T050910Z")
                  "2004-09-17T05:09:10+0000"))
-  (should (equal (icalendar-test--format "20040917T0509")
-                 "2004-09-17T03:09:00+0000"))
-  (should (equal (icalendar-test--format "20040917")
-                 "2004-09-16T22:00:00+0000"))
-  (should (equal (icalendar-test--format "20040917T050910" 1)
-                 "2004-09-18T03:09:10+0000"))
-  (should (equal (icalendar-test--format "20040917T050910" 30)
-                 "2004-10-17T03:09:10+0000"))
-  (should (equal (icalendar-test--format "20040917T050910" -1)
-                 "2004-09-16T03:09:10+0000"))
-
+  (should (equal (icalendar-test--format "20040917T050910" -1 0)
+                 "2004-09-16T05:09:10+0000"))
   (should (equal (icalendar-test--format "20040917T050910" nil -3600)
                  "2004-09-17T06:09:10+0000")))
 
-
 (provide 'icalendar-tests)
 ;;; icalendar-tests.el ends here