~rgrjr/rgr-hacks

39ee6cb2878a0e739e3f37db782db2460c2d7ddc — Bob Rogers 5 months ago 7340c9a
Fix parse-date hyphen handling

* parse-date.el:
   + (parse-date--tokenize-string):  Bug fix:  End the token only on
     only non-initial hyphens, and then be sure to skip over them.
* test/test-parse-date.el:
   + (parse-date-tests):  Add some hyphen (and other) tests.
2 files changed, 24 insertions(+), 6 deletions(-)

M parse-date.el
M test/test-parse-date.el
M parse-date.el => parse-date.el +11 -5
@@ 133,9 133,11 @@ first `(' (per RFC5322), else we strip them all (per RFC822)."
            (cl-incf index))
          (while (and (< (cl-incf index) end)
                      (setq char (aref string index))
		      ;; End the token on whitespace, a hyphen, or a comment.
                      (not (or (eq char ?-)
			       (parse-date--ignore-char? char)
		      ;; End the token on whitespace, a non-initial hyphen, or a
		      ;; comment.
                      (not (or (parse-date--ignore-char? char)
			       (and (> index start)
				    (eq char ?-))
                               (and strip-fws?
                                    (eq char ?\()))))
            (unless (<= ?0 char ?9)


@@ 149,6 151,10 @@ first `(' (per RFC5322), else we strip them all (per RFC822)."
                    (cl-parse-integer string :start start :end index)
                  (substring string start index))
                list)
          (when (and (> index start)
		     (eq char ?-))
	    ;; Skip a terminating hyphen.
	    (cl-incf index))
          (skip-ignored)))
      (nreverse list))))



@@ 161,8 167,8 @@ See the decoded-time defstruct.")
  '((0 60) (0 59) (0 23) (1 31) (1 12) (1 9999))
  "Numeric slot ranges, for bounds checking.
Note that RFC5322 explicitly requires that seconds go up to 60,
to allow for leap seconds (see Mills, D., 'Network Time
Protocol', STD 12, RFC 1119, September 1989).")
to allow for leap seconds (see Mills, D., \='Network Time
Protocol\=', STD 12, RFC 1119, September 1989).")

(defun parse-date--x822 (time-string obs-format?)
  ;; Parse an RFC5322 or (if obs-format? is true) RFC822 date.  The

M test/test-parse-date.el => test/test-parse-date.el +13 -1
@@ 8,6 8,7 @@
(require 'parse-date)

(ert-deftest parse-date-tests ()
  ;; RFC-822-like.
  (should (equal (parse-date "Mon, 22 Feb 2016 19:35:42 +0100")
                 '(42 35 19 22 2 2016 1 -1 3600)))
  (should (equal (parse-date "22 Feb 2016 19:35:42 +0100")


@@ 20,7 21,18 @@
                 '(42 35 19 22 2 2016 1 -1 3600)))
  (should (equal (parse-date "Monday, 22 february 2016 19:35:42 +0100")
                 '(42 35 19 22 2 2016 1 -1 3600)))
  ;; Alphabetic timezone.
  (should (equal (parse-date "Monday, 22 february 2016 19:35:42 PST")
                 '(42 35 19 22 2 2016 1 nil -28800)))
  (should (equal (parse-date "Friday, 21 Sep 2018 13:47:58 PDT")
                 '(58 47 13 21 9 2018 5 t -25200))))
                 '(58 47 13 21 9 2018 5 t -25200)))
  ;; No timezone.
  (should (equal (parse-date "Monday, 22 february 2016 19:35:42")
                 '(42 35 19 22 2 2016 1 -1 nil)))
  (should (equal (parse-date "Friday, 21 Sep 2018 13:47:58")
                 '(58 47 13 21 9 2018 5 -1 nil)))
  ;; Hyphens are also OK.
  (should (equal (parse-date "22-Feb-2016")
                 '(nil nil nil 22 2 2016 nil -1 nil)))
  (should (equal (parse-date "Feb-22-2016")
                 '(nil nil nil 22 2 2016 nil -1 nil))))