format-time-string

TSUCHIYA Masatoshi tsuchiya @ pine.kuee.kyoto-u.ac.jp
2001年 10月 11日 (木) 14:00:48 JST


%z をサポートしていない format-time-string() を built-in function とし
て持っている Emacsen のために、以下のような変更をしてはどうでしょうか。

-------------- next part --------------
--- poe.el	2001/04/29 12:34:03	1.73
+++ poe.el	2001/10/11 04:53:59
@@ -1166,7 +1166,8 @@
 ;;   %c, %C, %j, %U, %W, %x, %X
 ;; Not fully compatible especially when invalid format is specified.
 (static-unless (and (fboundp 'format-time-string)
-		    (not (get 'format-time-string 'defun-maybe)))
+		    (not (get 'format-time-string 'defun-maybe))
+		    (not (string= (format-time-string "%z" (current-time)) "z")))
   (or (fboundp 'format-time-string)
   (progn
   (defconst format-time-month-list
-------------- next part --------------

または、format-time-string() の本体には触らずに、%z のみを自前で処理す
る advice を定義するという手も考えられます。

(defadvice format-time-string
  (before support-timezone-in-numeric-form activate compile)
  "Advice to support the construct `%z' which will be replaced by the
timezone string in numeric form."
  (if (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))))))

こちらの方が、互換性問題が発生する可能性は低いと思いますが、どちらが良
いでしょうか?

-- 
土屋 雅稔  ( TSUCHIYA Masatoshi )


More information about the APEL-ja mailing list