aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-07-30 16:20:40 +0200
committerLars Ingebrigtsen2019-07-31 21:47:29 +0200
commit8c04e65622cbff1417727162d9b0c455cb87ed73 (patch)
tree338ec4459c05651f28e76a4b724da382bbfc578f
parent794f8f25b505ab32c7e79d1d484fce22e85c0010 (diff)
downloademacs-8c04e65622cbff1417727162d9b0c455cb87ed73.tar.gz
emacs-8c04e65622cbff1417727162d9b0c455cb87ed73.zip
Have newsticker use iso8601 to parse dates
* lisp/net/newst-backend.el (newsticker--decode-iso8601-date): Use iso8601 to parse.
-rw-r--r--lisp/net/newst-backend.el65
1 files changed, 10 insertions, 55 deletions
diff --git a/lisp/net/newst-backend.el b/lisp/net/newst-backend.el
index e356a0ece55..5064610e39c 100644
--- a/lisp/net/newst-backend.el
+++ b/lisp/net/newst-backend.el
@@ -37,6 +37,7 @@
37(require 'derived) 37(require 'derived)
38(require 'xml) 38(require 'xml)
39(require 'url-parse) 39(require 'url-parse)
40(require 'iso8601)
40 41
41;; Silence warnings 42;; Silence warnings
42(defvar w3-mode-map) 43(defvar w3-mode-map)
@@ -1594,61 +1595,15 @@ This function calls `message' with arguments STRING and ARGS, if
1594 ;;(not (current-message)) 1595 ;;(not (current-message))
1595 (apply 'message string args))) 1596 (apply 'message string args)))
1596 1597
1597(defun newsticker--decode-iso8601-date (iso8601-string) 1598(defun newsticker--decode-iso8601-date (string)
1598 "Return ISO8601-STRING in format like `decode-time'. 1599 "Return ISO8601-STRING in format like `encode-time'.
1599Converts from ISO-8601 to Emacs representation. 1600Converts from ISO-8601 to Emacs representation."
1600Examples: 1601 (if string
16012004-09-17T05:09:49.001+00:00 1602 (condition-case nil
16022004-09-17T05:09:49+00:00 1603 (encode-time (iso8601-parse string))
16032004-09-17T05:09+00:00 1604 (wrong-type-argument
16042004-09-17T05:09:49 1605 (message "Cannot decode \"%s\"" string)
16052004-09-17T05:09 1606 nil))
16062004-09-17
16072004-09
16082004"
1609 (if iso8601-string
1610 (when (string-match
1611 (concat
1612 "^ *\\([0-9]\\{4\\}\\)" ;year
1613 "\\(-\\([0-9]\\{2\\}\\)" ;month
1614 "\\(-\\([0-9]\\{2\\}\\)" ;day
1615 "\\(T"
1616 "\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)" ;hour:minute
1617 "\\(:\\([0-9]\\{2\\}\\)\\(\\.[0-9]+\\)?\\)?" ;second
1618 ;timezone
1619 "\\(\\([-+Z]\\)\\(\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)?"
1620 "\\)?\\)?\\)? *$")
1621 iso8601-string)
1622 (let ((year (read (match-string 1 iso8601-string)))
1623 (month (read (or (match-string 3 iso8601-string)
1624 "1")))
1625 (day (read (or (match-string 5 iso8601-string)
1626 "1")))
1627 (hour (read (or (match-string 7 iso8601-string)
1628 "0")))
1629 (minute (read (or (match-string 8 iso8601-string)
1630 "0")))
1631 (second (read (or (match-string 10 iso8601-string)
1632 "0")))
1633 (sign (match-string 13 iso8601-string))
1634 (offset-hour (read (or (match-string 15 iso8601-string)
1635 "0")))
1636 (offset-minute (read (or (match-string 16 iso8601-string)
1637 "0"))))
1638 (cond ((string= sign "+")
1639 (setq hour (- hour offset-hour))
1640 (setq minute (- minute offset-minute)))
1641 ((string= sign "-")
1642 (setq hour (+ hour offset-hour))
1643 (setq minute (+ minute offset-minute))))
1644 ;; if UTC subtract current-time-zone offset
1645 ;;(setq second (+ (car (current-time-zone)) second)))
1646
1647 (condition-case nil
1648 (encode-time second minute hour day month year t)
1649 (error
1650 (message "Cannot decode \"%s\"" iso8601-string)
1651 nil))))
1652 nil)) 1607 nil))
1653 1608
1654(defun newsticker--decode-rfc822-date (rfc822-string) 1609(defun newsticker--decode-rfc822-date (rfc822-string)