emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 6a87416 05/12: Use iso8601-parse in nnrss


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 6a87416 05/12: Use iso8601-parse in nnrss
Date: Wed, 31 Jul 2019 15:47:58 -0400 (EDT)

branch: master
commit 6a87416d61794af1bdde80f696a0595f215e7baa
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Use iso8601-parse in nnrss
    
    * lisp/gnus/nnrss.el (nnrss-normalize-date): Use iso8601-parse
    instead of hand-rolled parser.
    
    * test/lisp/gnus/nnrss-tests.el: New file.
---
 lisp/gnus/nnrss.el            | 51 ++++++++++++-------------------------------
 test/lisp/gnus/nnrss-tests.el | 29 ++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 37 deletions(-)

diff --git a/lisp/gnus/nnrss.el b/lisp/gnus/nnrss.el
index 0bfecb2..f2c86ee 100644
--- a/lisp/gnus/nnrss.el
+++ b/lisp/gnus/nnrss.el
@@ -36,6 +36,7 @@
 (require 'rfc2231)
 (require 'mm-url)
 (require 'rfc2047)
+(require 'iso8601)
 (require 'mml)
 (require 'xml)
 
@@ -468,49 +469,25 @@ which RSS 2.0 allows."
                        (not (string-match "\\`[A-Z+-]" zone)))
               (setq zone nil))))
          ;; ISO 8601
-         ((string-match
-           (eval-when-compile
-             (concat
-              ;; 1. year
-              "\\(199[0-9]\\|20[0-9][0-9]\\)"
-              "\\(?:-"
-              ;; 2. month
-              "\\([01][0-9]\\)"
-              "\\(?:-"
-              ;; 3. day
-              "\\([0-3][0-9]\\)"
-              "\\)?\\)?\\(?:T"
-              ;; 4. hh:mm
-              "\\([012][0-9]:[0-5][0-9]\\)"
-              "\\(?:"
-              ;; 5. :ss
-              "\\(:[0-5][0-9]\\)"
-              "\\(?:\\.[0-9]+\\)?\\)?\\)?"
-              ;; 6+7,8,9. zone
-              "\\(?:\\(?:\\([+-][012][0-9]\\):\\([0-5][0-9]\\)\\)"
-              "\\|\\([+-][012][0-9][0-5][0-9]\\)"
-              "\\|\\(Z\\)\\)?"))
-           date)
-          (setq year (string-to-number (match-string 1 date))
-                month (string-to-number (or (match-string 2 date) "1"))
-                day (string-to-number (or (match-string 3 date) "1"))
-                time (if (match-beginning 5)
-                         (substring date (match-beginning 4) (match-end 5))
-                       (concat (or (match-string 4 date) "00:00") ":00"))
-                zone (cond ((match-beginning 6)
-                            (concat (match-string 6 date)
-                                    (match-string 7 date)))
-                           ((match-beginning 9) ;; Z
-                            "+0000")
-                           (t ;; nil if zone is not provided.
-                            (match-string 8 date))))))
+         ((iso8601-valid-p date)
+          (let ((decoded (decoded-time-set-defaults (iso8601-parse date))))
+            (setq year (decoded-time-year decoded)
+                  month (decoded-time-month decoded)
+                  day (decoded-time-day decoded)
+                  time (format "%02d:%02d:%02d"
+                               (decoded-time-hour decoded)
+                               (decoded-time-minute decoded)
+                               (decoded-time-second decoded))
+                  zone (if (equal (decoded-time-zone decoded) "Z")
+                           0
+                         (decoded-time-zone decoded))))))
     (if month
        (progn
          (setq cts (current-time-string (encode-time 0 0 0 day month year)))
          (format "%s, %02d %s %04d %s%s"
                  (substring cts 0 3) day (substring cts 4 7) year time
                  (if zone
-                     (concat " " zone)
+                     (concat " " (time-zone-format zone t))
                    "")))
       (message-make-date given))))
 
diff --git a/test/lisp/gnus/nnrss-tests.el b/test/lisp/gnus/nnrss-tests.el
new file mode 100644
index 0000000..184c592
--- /dev/null
+++ b/test/lisp/gnus/nnrss-tests.el
@@ -0,0 +1,29 @@
+;;; nnrss-tests.el --- tests for gnus/nnrss.el    -*- lexical-binding:t -*-
+
+;; Copyright (C) 2019 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'nnrss)
+
+(ert-deftest test-nnrss-normalize ()
+  (should (equal (nnrss-normalize-date "2004-09-17T05:09:49.001+00:00")
+                 "Fri, 17 Sep 2004 05:09:49 +0000")))
+
+;;; nnrss-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]