From: Ulrich Mueller <ulm@gentoo.org>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: Eli Zaretskii <eliz@gnu.org>, 72570@debbugs.gnu.org
Subject: bug#72570: 31.0.50; Regression in date-to-time
Date: Wed, 14 Aug 2024 16:09:13 +0200 [thread overview]
Message-ID: <u5xs3w60m@gentoo.org> (raw)
In-Reply-To: <1513da6b-20a3-4033-b433-6f13b38c348d@cs.ucla.edu> (Paul Eggert's message of "Tue, 13 Aug 2024 14:19:06 -0700")
[-- Attachment #1: Type: text/plain, Size: 292 bytes --]
>>>>> On Tue, 13 Aug 2024, Paul Eggert wrote:
> If that's the only reason it's there, we can simply remove the call to
> timezone-make-date-arpa-standard. That would be better to coating the
> pig with even more lipstick.
The attached patch does the former, and also adds some test cases.
[-- Attachment #2: 0001-Drop-fallback-code-in-date-to-time-update-documentat.patch --]
[-- Type: text/plain, Size: 5113 bytes --]
From ccb2d7282cb792ae993b94821ae7bf1d79f4d348 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ulrich=20M=C3=BCller?= <ulm@gentoo.org>
Date: Wed, 14 Aug 2024 13:57:16 +0200
Subject: [PATCH] Drop fallback code in date-to-time, update documentation
* lisp/calendar/time-date.el (date-to-time): Drop fallback code.
Document that the default timezone is local time, rather than GMT.
* test/lisp/calendar/time-date-tests.el (test-date-to-time):
Add more test cases.
* doc/lispref/os.texi (Time Parsing): Document that 'date-to-time'
defaults to local time. (Bug#72570)
---
doc/lispref/os.texi | 4 ++--
lisp/calendar/time-date.el | 19 ++++---------------
test/lisp/calendar/time-date-tests.el | 24 ++++++++++++++++++++++--
3 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index 5839de4a650..ddaa1de221c 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -1788,8 +1788,8 @@ Time Parsing
This function parses the time-string @var{string} and returns the
corresponding Lisp timestamp. The argument @var{string} should represent
a date-time, and should be in one of the forms recognized by
-@code{parse-time-string} (see below). This function assumes Universal
-Time if @var{string} lacks explicit time zone information,
+@code{parse-time-string} (see below). This function assumes local time
+if @var{string} lacks explicit time zone information,
and assumes earliest values if @var{string} lacks month, day, or time.
The operating system limits the range of time and zone values.
@end defun
diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el
index eca80f1e8b6..717cb4a5c5b 100644
--- a/lisp/calendar/time-date.el
+++ b/lisp/calendar/time-date.el
@@ -145,30 +145,19 @@ encode-time-value
(autoload 'timezone-make-date-arpa-standard "timezone")
;;;###autoload
-;; `parse-time-string' isn't sufficiently general or robust. It fails
-;; to grok some of the formats that timezone does (e.g. dodgy
-;; post-2000 stuff from some Elms) and either fails or returns bogus
-;; values. timezone-make-date-arpa-standard should help.
(defun date-to-time (date)
"Parse a string DATE that represents a date-time and return a time value.
DATE should be in one of the forms recognized by `parse-time-string'.
-If DATE lacks timezone information, GMT is assumed."
+If DATE lacks timezone information, local time is assumed."
(condition-case err
(let ((parsed (parse-time-string date)))
(when (decoded-time-year parsed)
(decoded-time-set-defaults parsed))
(encode-time parsed))
(error
- (let ((overflow-error '(error "Specified time is not representable")))
- (if (equal err overflow-error)
- (signal (car err) (cdr err))
- (condition-case err
- (encode-time (parse-time-string
- (timezone-make-date-arpa-standard date)))
- (error
- (if (equal err overflow-error)
- (signal (car err) (cdr err))
- (error "Invalid date: %s" date)))))))))
+ (if (equal err '(error "Specified time is not representable"))
+ (signal (car err) (cdr err))
+ (error "Invalid date: %s" date)))))
;;;###autoload
(defalias 'time-to-seconds #'float-time)
diff --git a/test/lisp/calendar/time-date-tests.el b/test/lisp/calendar/time-date-tests.el
index 6512dd0bd07..f8e434e17b1 100644
--- a/test/lisp/calendar/time-date-tests.el
+++ b/test/lisp/calendar/time-date-tests.el
@@ -42,8 +42,28 @@ test-obsolete-encode-time-value
'(1 2 3 4))))
(ert-deftest test-date-to-time ()
- (should (equal (format-time-string "%F %T" (date-to-time "2021-12-04"))
- "2021-12-04 00:00:00")))
+ (let ((date-list
+ '(("2021-12-04" (00 00 00 04 12 2021 nil -1 nil))
+ ("2006-05-04T03:02:01Z" (01 02 03 04 05 2006 nil nil 0))
+ ;; Test cases from timezone-parse-date docstring
+ ("14 Apr 89 03:20" (00 20 03 14 04 1989 nil -1 nil))
+ ("14 Apr 89 03:20:12 GMT" (12 20 03 14 04 1989 nil nil 0))
+ ("Fri, 17 Mar 89 4:01" (00 01 04 17 03 1989 nil -1 nil))
+ ("Fri, 17 Mar 89 4:01:33 GMT" (33 01 04 17 03 1989 nil nil 0))
+ ("Mon Jan 16 16:12 1989" (00 12 16 16 01 1989 nil -1 nil))
+ ("Mon Jan 16 16:12:37 GMT 1989" (37 12 16 16 01 1989 nil nil 0))
+ ("Thu, 11 Apr 16:17:12 91" (12 17 16 11 04 1991 nil -1 nil))
+ ("Mon, 6 Jul 16:47:20 T 1992" (20 47 16 06 07 1992 nil -1 nil))
+ ("1996-06-24 21:13:12" (12 13 21 24 06 1996 nil -1 nil))
+ ("19960624t211312" (12 13 21 24 06 1996 nil -1 nil))
+ ;; These are parsed incorrectly:
+ ;; "6 May 1992 1641-JST (Wednesday)"
+ ;; "22-AUG-1993 10:59:12.82"
+ ;; "1996-06-24 21:13-ZONE"
+ )))
+ (dolist (date date-list)
+ (should (equal (date-to-time (car date))
+ (encode-time (cadr date)))))))
(ert-deftest test-days-between ()
(should (equal (days-between "2021-10-22" "2020-09-29") 388)))
--
2.45.2
next prev parent reply other threads:[~2024-08-14 14:09 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-11 8:57 bug#72570: 31.0.50; Regression in date-to-time Ulrich Mueller
2024-08-12 7:27 ` Ulrich Mueller
2024-08-12 8:18 ` Ulrich Mueller
2024-08-12 11:42 ` Eli Zaretskii
2024-08-12 12:51 ` Ulrich Mueller
2024-08-12 13:26 ` Eli Zaretskii
2024-08-12 13:48 ` Ulrich Mueller
2024-08-12 14:30 ` Eli Zaretskii
2024-08-12 22:03 ` Paul Eggert
2024-08-13 5:55 ` Ulrich Mueller
2024-08-13 19:39 ` Paul Eggert
2024-08-13 21:11 ` Ulrich Mueller
2024-08-13 21:19 ` Paul Eggert
2024-08-14 8:12 ` Ulrich Mueller
2024-08-14 14:09 ` Ulrich Mueller [this message]
2024-08-15 3:27 ` Paul Eggert
2024-08-15 4:35 ` Ulrich Mueller
2024-08-15 6:26 ` Paul Eggert
2024-08-15 6:45 ` Eli Zaretskii
2024-08-15 7:18 ` Ulrich Mueller
2024-08-15 7:22 ` Eli Zaretskii
2024-08-13 11:15 ` Eli Zaretskii
2024-08-13 15:09 ` Ulrich Mueller
2024-08-13 15:36 ` Eli Zaretskii
2024-08-13 19:59 ` Paul Eggert
2024-08-14 8:37 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=u5xs3w60m@gentoo.org \
--to=ulm@gentoo.org \
--cc=72570@debbugs.gnu.org \
--cc=eggert@cs.ucla.edu \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).