From a9e39e9dc0b816e3ba2798531ccd5e7bcb494075 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 3 Aug 2014 23:56:45 +0000 Subject: [PATCH] parse-time.el (parse-time-rules), time-date.el (date-to-time): Don't mishandle year-9999 dates (Bug#18176) --- lisp/ChangeLog | 8 ++++++++ lisp/parse-time.el | 2 +- lisp/time-date.el | 19 +++++++++++++------ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index b8709941a..333c3b64f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2014-08-03 Paul Eggert + + Don't mishandle year-9999 dates (Bug#18176). + * parse-time.el (parse-time-rules): + Allow years up to most-positive-fixnum. + * time-date.el (date-to-time): + Pass "Specified time is not representable" errors through. + 2014-07-31 Tassilo Horn * gnus-msg.el (gnus-inews-insert-gcc): Allow `gcc-self' to be a list of diff --git a/lisp/parse-time.el b/lisp/parse-time.el index 42b499130..85b8ef173 100644 --- a/lisp/parse-time.el +++ b/lisp/parse-time.el @@ -151,7 +151,7 @@ `(((6) parse-time-weekdays) ((3) (1 31)) ((4) parse-time-months) - ((5) (100 4038)) + ((5) (100 ,most-positive-fixnum)) ((2 1 0) ,#'(lambda () (and (stringp parse-time-elt) (= (length parse-time-elt) 8) diff --git a/lisp/time-date.el b/lisp/time-date.el index b04cfcd9f..48fe22943 100644 --- a/lisp/time-date.el +++ b/lisp/time-date.el @@ -119,13 +119,20 @@ it is assumed that PICO was omitted and should be treated as zero." (defun date-to-time (date) "Parse a string DATE that represents a date-time and return a time value. If DATE lacks timezone information, GMT is assumed." - (condition-case () + (condition-case err (apply 'encode-time (parse-time-string date)) - (error (condition-case () - (apply 'encode-time - (parse-time-string - (timezone-make-date-arpa-standard date))) - (error (error "Invalid date: %s" date)))))) + (error + (let ((overflow-error '(error "Specified time is not representable"))) + (if (equal err overflow-error) + (apply 'signal err) + (condition-case err + (apply 'encode-time + (parse-time-string + (timezone-make-date-arpa-standard date))) + (error + (if (equal err overflow-error) + (apply 'signal err) + (error "Invalid date: %s" date))))))))) ;; Bit of a mess. Emacs has float-time since at least 21.1. ;; This file is synced to Gnus, and XEmacs packages may have been written -- 2.25.1