From c8f1e17e6be1545557f10c3e8039e655ace6ab1c Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Wed, 31 Jul 2019 15:25:46 +0200 Subject: [PATCH] Rewrite `url-dav-process-date-property' to use parse-time * lisp/url/url-dav.el (url-dav-iso8601-regexp): Remove. (url-dav-process-date-property): Rewrite to use `parse-iso8601-time-string'. --- lisp/url/url-dav.el | 67 ++++----------------------------------------- 1 file changed, 5 insertions(+), 62 deletions(-) diff --git a/lisp/url/url-dav.el b/lisp/url/url-dav.el index a4cf0f0ec01..3159b695c14 100644 --- a/lisp/url/url-dav.el +++ b/lisp/url/url-dav.el @@ -33,6 +33,7 @@ (require 'url-util) (require 'url-handlers) (require 'url-http) +(require 'parse-time) (defvar url-dav-supported-protocols '(1 2) "List of supported DAV versions.") @@ -83,72 +84,14 @@ Returns nil if WebDAV is not supported." (defun url-dav-process-number-property (node) (string-to-number (url-dav-node-text node))) -(defconst url-dav-iso8601-regexp - (let* ((dash "-?") - (colon ":?") - (4digit "\\([0-9][0-9][0-9][0-9]\\)") - (2digit "\\([0-9][0-9]\\)") - (date-fullyear 4digit) - (date-month 2digit) - (date-mday 2digit) - (time-hour 2digit) - (time-minute 2digit) - (time-second 2digit) - (time-secfrac "\\(\\.[0-9]+\\)?") - (time-numoffset (concat "[-+]\\(" time-hour "\\):" time-minute)) - (time-offset (concat "Z" time-numoffset)) - (partial-time (concat time-hour colon time-minute colon time-second - time-secfrac)) - (full-date (concat date-fullyear dash date-month dash date-mday)) - (full-time (concat partial-time time-offset)) - (date-time (concat full-date "T" full-time))) - (list (concat "^" full-date) - (concat "T" partial-time) - (concat "Z" time-numoffset))) - "List of regular expressions matching ISO 8601 dates. -1st regular expression matches the date. -2nd regular expression matches the time. -3rd regular expression matches the (optional) timezone specification.") - (defun url-dav-process-date-property (node) - (require 'parse-time) - (let* ((date-re (nth 0 url-dav-iso8601-regexp)) - (time-re (nth 1 url-dav-iso8601-regexp)) - (tz-re (nth 2 url-dav-iso8601-regexp)) - (date-string (url-dav-node-text node)) - re-start - time seconds minute hour fractional-seconds - day month year day-of-week dst tz) - ;; We need to populate 'time' with - ;; (SEC MIN HOUR DAY MON YEAR DOW DST TZ) - - ;; Nobody else handles iso8601 correctly, let's do it ourselves. - (when (string-match date-re date-string re-start) - (setq year (string-to-number (match-string 1 date-string)) - month (string-to-number (match-string 2 date-string)) - day (string-to-number (match-string 3 date-string)) - re-start (match-end 0)) - (when (string-match time-re date-string re-start) - (setq hour (string-to-number (match-string 1 date-string)) - minute (string-to-number (match-string 2 date-string)) - seconds (string-to-number (match-string 3 date-string)) - fractional-seconds (string-to-number (or - (match-string 4 date-string) - "0")) - re-start (match-end 0)) - (when (string-match tz-re date-string re-start) - (setq tz (match-string 1 date-string))) - (url-debug 'dav "Parsed iso8601%s date" (if tz "tz" "")) - (setq time (list seconds minute hour day month year day-of-week dst tz)))) - - ;; Fall back to having Gnus do fancy things for us. - (when (not time) - (setq time (parse-time-string date-string))) - + (let* ((date-string (url-dav-node-text node)) + (time (parse-iso8601-time-string date-string))) (if time (setq time (encode-time time)) (url-debug 'dav "Unable to decode date (%S) (%s)" - (xml-node-name node) date-string)) + (xml-node-name node) + date-string)) time)) (defun url-dav-process-boolean-property (node) -- 2.39.2