aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorPaul Eggert2016-04-12 09:19:11 -0700
committerPaul Eggert2016-04-12 09:19:38 -0700
commitfdb1ba144ca61185e6457f092f38f59dd9bbe6a0 (patch)
tree5048d1fbb946faf0b6059e4d4375bb514b3bfa74 /lisp
parent7c2c2196fd4be0b656bdf0e0b68f3d7c4a5eca08 (diff)
downloademacs-fdb1ba144ca61185e6457f092f38f59dd9bbe6a0.tar.gz
emacs-fdb1ba144ca61185e6457f092f38f59dd9bbe6a0.zip
Support OFFSET and (OFFSET ABBR) time zone rules
This simplifies Gnus and VC time zone support, by letting them feed the output of ‘current-time-zone’ and ‘decode time’ to primitives that accept time zone arguments. * doc/lispref/os.texi (Time Zone Rules, Time Conversion): * etc/NEWS: * lisp/gnus/message.el (message-insert-formatted-citation-line): * lisp/org/org.el (org-timestamp-format): * src/editfns.c (Fformat_time_string, Fdecode_time): (Fcurrent_time_string, Fcurrent_time_zone, Fset_time_zone_rule): Document new behavior. * lisp/gnus/gmm-utils.el (gmm-format-time-string): * lisp/vc/add-log.el (add-log-iso8601-time-zone): Mark as obsolete, as it is now just an alias or narrow wrapper around format-time-string. * src/editfns.c (tzlookup): Also support integer OFFSET and list (OFFSET ABBR) as time zone rules. (Fencode_time): No longer need a special case for a cons ZONE. (Fcurrent_time_zone): If the time zone string is missing, compute it the same way the other new code does.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/gnus/gmm-utils.el33
-rw-r--r--lisp/gnus/message.el9
-rw-r--r--lisp/org/org.el6
-rw-r--r--lisp/vc/add-log.el19
4 files changed, 17 insertions, 50 deletions
diff --git a/lisp/gnus/gmm-utils.el b/lisp/gnus/gmm-utils.el
index f6455cf9f1a..7aa52794e4c 100644
--- a/lisp/gnus/gmm-utils.el
+++ b/lisp/gnus/gmm-utils.el
@@ -256,37 +256,8 @@ If mode is nil, use `major-mode' of the current buffer."
256 (string-match "^\\(.+\\)-mode$" mode) 256 (string-match "^\\(.+\\)-mode$" mode)
257 (match-string 1 mode)))))) 257 (match-string 1 mode))))))
258 258
259(defun gmm-format-time-string (format-string &optional time tz) 259(define-obsolete-function-alias 'gmm-format-time-string 'format-time-string
260 "Use FORMAT-STRING to format the time TIME, or now if omitted. 260 "25.2")
261The optional TZ specifies the time zone in a number of seconds; any
262other non-nil value will be treated as 0. Note that both the format
263specifiers `%Z' and `%z' will be replaced with a numeric form. "
264;; FIXME: is there a smart way to replace %Z with a time zone name?
265 (if (and (numberp tz) (not (zerop tz)))
266 (let ((st 0)
267 (case-fold-search t)
268 ls nd rest)
269 (setq time (if time
270 (copy-sequence time)
271 (current-time)))
272 (if (>= (setq ls (- (cadr time) (car (current-time-zone)) (- tz))) 0)
273 (setcar (cdr time) ls)
274 (setcar (cdr time) (+ ls 65536))
275 (setcar time (1- (car time))))
276 (setq tz (format "%s%02d%02d"
277 (if (>= tz 0) "+" "-")
278 (/ (abs tz) 3600)
279 (/ (% (abs tz) 3600) 60)))
280 (while (string-match "%+z" format-string st)
281 (if (zerop (% (- (setq nd (match-end 0)) (match-beginning 0)) 2))
282 (progn
283 (push (substring format-string st (- nd 2)) rest)
284 (push tz rest))
285 (push (substring format-string st nd) rest))
286 (setq st nd))
287 (push (substring format-string st) rest)
288 (format-time-string (apply 'concat (nreverse rest)) time))
289 (format-time-string format-string time t)))
290 261
291(provide 'gmm-utils) 262(provide 'gmm-utils)
292 263
diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index 14d8d30f8af..32d740b0190 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -3879,8 +3879,13 @@ This function uses `mail-citation-hook' if that is non-nil."
3879(defun message-insert-formatted-citation-line (&optional from date tz) 3879(defun message-insert-formatted-citation-line (&optional from date tz)
3880 "Function that inserts a formatted citation line. 3880 "Function that inserts a formatted citation line.
3881The optional FROM, and DATE are strings containing the contents of 3881The optional FROM, and DATE are strings containing the contents of
3882the From header and the Date header respectively. The optional TZ 3882the From header and the Date header respectively.
3883is a number of seconds, overrides the time zone of DATE. 3883
3884The optional TZ is omitted or nil for Emacs local time, t for
3885Universal Time, `wall' for system wall clock time, or a string as
3886in the TZ environment variable. It can also be a list (as from
3887`current-time-zone') or an integer (as from `decode-time')
3888applied without consideration for daylight saving time.
3884 3889
3885See `message-citation-line-format'." 3890See `message-citation-line-format'."
3886 ;; The optional args are for testing/debugging. They will disappear later. 3891 ;; The optional args are for testing/debugging. They will disappear later.
diff --git a/lisp/org/org.el b/lisp/org/org.el
index 231daa9a6a7..3abf62704bb 100644
--- a/lisp/org/org.el
+++ b/lisp/org/org.el
@@ -22673,8 +22673,10 @@ When optional argument END is non-nil, use end of date-range or
22673time-range, if possible. 22673time-range, if possible.
22674 22674
22675The optional ZONE is omitted or nil for Emacs local time, t for 22675The optional ZONE is omitted or nil for Emacs local time, t for
22676Universal Time, `wall' for system wall clock time, or a string as in 22676Universal Time, `wall' for system wall clock time, or a string as
22677the TZ environment variable." 22677in the TZ environment variable. It can also be a list (as from
22678`current-time-zone') or an integer (as from `decode-time')
22679applied without consideration for daylight saving time."
22678 (format-time-string 22680 (format-time-string
22679 format 22681 format
22680 (apply 'encode-time 22682 (apply 'encode-time
diff --git a/lisp/vc/add-log.el b/lisp/vc/add-log.el
index 58a4e77a602..9076d834c7c 100644
--- a/lisp/vc/add-log.el
+++ b/lisp/vc/add-log.el
@@ -590,25 +590,14 @@ If a string, interpret as the ZONE argument of `format-time-string'.")
590 (lambda (x) (or (booleanp x) (stringp x)))) 590 (lambda (x) (or (booleanp x) (stringp x))))
591 591
592(defun add-log-iso8601-time-zone (&optional time zone) 592(defun add-log-iso8601-time-zone (&optional time zone)
593 (let* ((utc-offset (or (car (current-time-zone time zone)) 0)) 593 (declare (obsolete nil "25.2"))
594 (sign (if (< utc-offset 0) ?- ?+)) 594 (format-time-string "%:::z" time zone))
595 (sec (abs utc-offset))
596 (ss (% sec 60))
597 (min (/ sec 60))
598 (mm (% min 60))
599 (hh (/ min 60)))
600 (format (cond ((not (zerop ss)) "%c%02d:%02d:%02d")
601 ((not (zerop mm)) "%c%02d:%02d")
602 (t "%c%02d"))
603 sign hh mm ss)))
604 595
605(defvar add-log-iso8601-with-time-zone nil) 596(defvar add-log-iso8601-with-time-zone nil)
606 597
607(defun add-log-iso8601-time-string (&optional time zone) 598(defun add-log-iso8601-time-string (&optional time zone)
608 (let ((date (format-time-string "%Y-%m-%d" time zone))) 599 (format-time-string
609 (if add-log-iso8601-with-time-zone 600 (if add-log-iso8601-with-time-zone "%Y-%m-%d %:::z" "%Y-%m-%d") time zone))
610 (concat date " " (add-log-iso8601-time-zone time zone))
611 date)))
612 601
613(defun change-log-name () 602(defun change-log-name ()
614 "Return (system-dependent) default name for a change log file." 603 "Return (system-dependent) default name for a change log file."