DEF, if non-nil, is the default value.
Completion ignores case if the ambient value of
- `completion-ignore-case' is non-nil."
+ `completion-ignore-case' is non-nil."
(let ((string (si:completing-read prompt table predicate
require-match init hist)))
(if (and (string= string "") def)
(buffer-string)))
(si:replace-match newtext fixedcase literal)))))))))
-;; Emacs 20: (format-time-string)
-;; The the third optional argument universal is yet to be implemented.
+;; Emacs 20: (format-time-string FORMAT &optional TIME UNIVERSAL)
;; Those format constructs are yet to be implemented.
;; %c, %C, %j, %U, %W, %x, %X
;; Not fully compatible especially when invalid format is specified.
Compatibility Note.
-The the third optional argument universal is yet to be implemented.
Those format constructs are yet to be implemented.
%c, %C, %j, %U, %W, %x, %X
Not fully compatible especially when invalid format is specified."
field-result
pad-left change-case
(paren-level 0)
- hour
- (time-string (current-time-string time)))
- (setq hour (string-to-int (substring time-string 11 13)))
+ hour ms ls
+ (tz (car (current-time-zone)))
+ time-string)
+ (if universal
+ (progn
+ (or time
+ (setq time (current-time)))
+ (setq ms (car time)
+ ls (- (nth 1 time) tz))
+ (cond ((< ls 0)
+ (setq ms (1- ms)
+ ls (+ ls 65536)))
+ ((>= ls 65536)
+ (setq ms (1+ ms)
+ ls (- ls 65536))))
+ (setq time (append (list ms ls) (nth 2 time)))))
+ (setq time-string (current-time-string time)
+ hour (string-to-int (substring time-string 11 13)))
(while (< ind fmt-len)
(setq cur-char (aref format ind))
(setq
(cond
((eq cur-char ?%)
"%")
- ;; the abbreviated name of the day of week.
+ ;; the abbreviated name of the day of week.
((eq cur-char ?a)
(substring time-string 0 3))
;; the full name of the day of week
((eq cur-char ?C)
"")
;; the day of month, zero-padded
- ((eq cur-char ?d)
+ ((eq cur-char ?d)
(format "%02d" (string-to-int (substring time-string 8 10))))
;; a synonym for `%m/%d/%y'
((eq cur-char ?D)
(substring time-string 11 13)
(substring time-string 14 16)
(substring time-string 17 19)))
- ;; the week of the year (01-52), assuming that weeks
+ ;; the week of the year (01-52), assuming that weeks
;; start on Sunday (yet to come)
((eq cur-char ?U)
"")
(substring time-string -4))
;; the time zone abbreviation
((eq cur-char ?Z)
- (setq change-case (not change-case))
- (downcase (cadr (current-time-zone))))
+ (if universal
+ "UTC"
+ (setq change-case (not change-case))
+ (downcase (cadr (current-time-zone)))))
((eq cur-char ?z)
- (let ((tz (car (current-time-zone))))
+ (if universal
+ "+0000"
(if (< tz 0)
- (format "-%02d%02d" (/ (- tz) 3600) (/ (% (- tz) 3600) 60))
- (format "+%02d%02d" (/ tz 3600) (/ (% tz 3600) 60)))))
+ (format "-%02d%02d"
+ (/ (- tz) 3600) (/ (% (- tz) 3600) 60))
+ (format "+%02d%02d"
+ (/ tz 3600) (/ (% tz 3600) 60)))))
(t
(concat
"%"
(setq current-load-list (cons 'format-time-string current-load-list))
(put 'format-time-string 'defun-maybe t))))
-;; Emacs 19.29-19.34/XEmacs: format-time-string() doesn't support `%z'.
+;; Emacs 19.29-19.34/XEmacs: `format-time-string' neither supports the
+;; format string "%z" nor the third argument `universal'.
(unless (string-match "\\`[\\-\\+][0-9]+\\'"
(format-time-string "%z" (current-time)))
(defadvice format-time-string
- (before support-timezone-in-numeric-form activate compile)
- "Advice to support the construct `%z'."
- (if (let ((case-fold-search nil))
- (string-match "\\(\\(\\`\\|[^%]\\)\\(%%\\)*\\)%z" (ad-get-arg 0)))
- (ad-set-arg
- 0
- (concat
- (substring (ad-get-arg 0) 0 (match-end 1))
- (let ((tz (car (current-time-zone))))
- (if (< tz 0)
- (format "-%02d%02d" (/ (- tz) 3600) (/ (% (- tz) 3600) 60))
- (format "+%02d%02d" (/ tz 3600) (/ (% tz 3600) 60))))
- (substring (ad-get-arg 0) (match-end 0)))))))
+ (before support-timezone-in-numeric-form-and-3rd-arg
+ (format-string &optional time universal) activate compile)
+ "Advice to support the construct `%z' and the third argument `universal'."
+ (let ((tz (car (current-time-zone)))
+ case-fold-search ms ls)
+ (while (string-match "\\(\\(\\`\\|[^%]\\)\\(%%\\)*\\)%z" format-string)
+ (setq format-string
+ (concat (substring format-string 0 (match-end 1))
+ (if universal
+ "+0000"
+ (if (< tz 0)
+ (format "-%02d%02d"
+ (/ (- tz) 3600) (/ (% (- tz) 3600) 60))
+ (format "+%02d%02d"
+ (/ tz 3600) (/ (% tz 3600) 60))))
+ (substring format-string (match-end 0)))))
+ (if universal
+ (progn
+ (while (string-match "\\(\\(\\`\\|[^%]\\)\\(%%\\)*\\)%Z"
+ format-string)
+ (setq format-string
+ (concat (substring format-string 0 (match-end 1))
+ "UTC"
+ (substring format-string (match-end 0)))))
+ (or time
+ (setq time (current-time)))
+ (setq ms (car time)
+ ls (- (nth 1 time) tz))
+ (cond ((< ls 0)
+ (setq ms (1- ms)
+ ls (+ ls 65536)))
+ ((>= ls 65536)
+ (setq ms (1+ ms)
+ ls (- ls 65536))))
+ (setq time (append (list ms ls) (nth 2 time))))))))
;; Emacs 20.1/XEmacs 20.3(?) and later: (split-string STRING &optional PATTERN)
;; Here is a XEmacs version.