~brettgilio/org-webring

d48dcc3bd62a7df2117466e49e29dd0b2dd6e79a — Ivan Sokolov 16 days ago 48c01da
ix parsing of Atom pub dates in 27.1

Co-authored-by: Brett Gilio <brettg@gnu.org>
1 files changed, 21 insertions(+), 16 deletions(-)

M org-webring.el
M org-webring.el => org-webring.el +21 -16
@@ 12,7 12,7 @@
;; Co-author: Amin Bandali <bandali@gnu.org>
;; Co-author: Ivan Sokolov <ivan-p-sokolov@ya.ru>

;; Version: 1.6
;; Version: 1.7

;; Homepage: https://sr.ht/~brettgilio/org-webring
;; Repository: https://git.sr.ht/~brettgilio/org-webring


@@ 66,9 66,6 @@
(require 'xml)
(require 'xmlgen)

(when (>= emacs-major-version 27)
  (require 'iso8601))

(defconst org-webring-attribution-name
  "org-webring"
  "The name of the program used to generate the webring.")


@@ 83,7 80,7 @@
  "Used to track the originating directory of asset files.")

(defconst org-webring-version
  "1.6"
  "1.7"
  "The current version of org-webring.")

(defcustom org-webring-items-total 3


@@ 235,23 232,31 @@ end. Taken from the s.el library."
      (format "%s%s" (substring s 0 (- len (length elipsis))) elipsis)
    s))

(defun org-webring--parse-datetime (datetime atom-p)
  "Convert string DATETIME to a list of components.
ATOM-P enables ISO8601 parsing."
  (if (not atom-p)
      (parse-time-string datetime)
    ;; This check is unnecessary for Emacs 28, but in Emacs 27
    ;; `parse-time-string' does not yet understand ISO8601.
    ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=43175
    (if (require 'iso8601 nil t)
        (iso8601-parse datetime)
      ;; Fallback for Emacs 26.3 and earlier
      (thread-first datetime
        (substring 0 19)
        (split-string "T")
        (string-join " ")
        (concat " +0000")
        (parse-time-string)))))

(defun org-webring--date->time (date &optional atom-p)
  "Convert DATE string to a time value.

Rudimentary support for parsing ISO-8601 time strings is used
when ATOM-P is non-nil and the function `iso8601-parse' (which
was introduced in Emacs 27) isn't available."
  (apply 'encode-time
	 (parse-time-string
	  (cond ((fboundp #'iso8601-parse) date)
		(atom-p (concat
			 (mapconcat #'identity
				    ;; TODO: Eventually replace hard-coded string
				    ;; index values with something more elegant.
				    (split-string (substring date 0 19) "T")
				    " ")
			 " +0000"))
		(t date)))))
  (apply #'encode-time (org-webring--parse-datetime date atom-p)))

(defun org-webring--pub-time (item)
  "Get ITEM's publication time."