X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=elmo%2Felmo-date.el;h=7d986ea1713d7118883fb81a16cba72004d535cd;hb=382d7519f582a3d8dc6b524b5bf002510bcc9338;hp=ea2f0e577f9575ef74de0c322bc1f97b9908433e;hpb=8d56bd754fd5060c731102293a32db2ddd2508ab;p=elisp%2Fwanderlust.git diff --git a/elmo/elmo-date.el b/elmo/elmo-date.el index ea2f0e5..7d986ea 100644 --- a/elmo/elmo-date.el +++ b/elmo/elmo-date.el @@ -33,21 +33,22 @@ (require 'path-util) (require 'timezone) (require 'elmo-vars) +(eval-when-compile (require 'cl)) (defmacro elmo-match-substring (pos string from) "Substring of POSth matched string of STRING." - (` (substring (, string) - (+ (match-beginning (, pos)) (, from)) - (match-end (, pos))))) + `(substring ,string + (+ (match-beginning ,pos) ,from) + (match-end ,pos))) (defmacro elmo-match-string (pos string) "Substring POSth matched STRING." - (` (substring (, string) (match-beginning (, pos)) (match-end (, pos))))) + `(substring ,string (match-beginning ,pos) (match-end ,pos))) (defmacro elmo-match-buffer (pos) "Substring POSth matched from the current buffer." - (` (buffer-substring-no-properties - (match-beginning (, pos)) (match-end (, pos))))) + `(buffer-substring-no-properties + (match-beginning ,pos) (match-end ,pos))) ;; from subr.el (defun elmo-replace-in-string (str regexp newtext &optional literal) @@ -71,24 +72,23 @@ Otherwise treat \\ in NEWTEXT string as special: (substring str prev-start match) (cond (literal newtext) (t (mapconcat - (function - (lambda (c) - (if special - (progn - (setq special nil) - (cond ((eq c ?\\) "\\") - ((eq c ?&) - (elmo-match-string 0 str)) - ((and (>= c ?0) (<= c ?9)) - (if (> c (+ ?0 (length - (match-data)))) - ;; Invalid match num - (error "Invalid match num: %c" c) - (setq c (- c ?0)) - (elmo-match-string c str))) - (t (char-to-string c)))) - (if (eq c ?\\) (progn (setq special t) nil) - (char-to-string c))))) + (lambda (c) + (if special + (progn + (setq special nil) + (cond ((eq c ?\\) "\\") + ((eq c ?&) + (elmo-match-string 0 str)) + ((and (>= c ?0) (<= c ?9)) + (if (> c (+ ?0 (length + (match-data)))) + ;; Invalid match num + (error "Invalid match num: %c" c) + (setq c (- c ?0)) + (elmo-match-string c str))) + (t (char-to-string c)))) + (if (eq c ?\\) (progn (setq special t) nil) + (char-to-string c)))) newtext "")))))) (concat rtn-str (substring str start)))) @@ -115,7 +115,7 @@ Otherwise treat \\ in NEWTEXT string as special: (timezone-fix-time (current-time-string) (current-time-zone) nil))) (number - (string-to-int + (string-to-number (if (match-beginning 1) (elmo-match-string 1 description) "0"))) @@ -202,14 +202,87 @@ Otherwise treat \\ in NEWTEXT string as special: (defmacro elmo-date-make-sortable-string (datevec) "Make a sortable string from DATEVEC." - (` (timezone-make-sortable-date - (aref (, datevec) 0) - (aref (, datevec) 1) - (aref (, datevec) 2) - (timezone-make-time-string - (aref (, datevec) 3) - (aref (, datevec) 4) - (aref (, datevec) 5))))) + `(timezone-make-sortable-date + (aref ,datevec 0) + (aref ,datevec 1) + (aref ,datevec 2) + (timezone-make-time-string + (aref ,datevec 3) + (aref ,datevec 4) + (aref ,datevec 5)))) + +(defsubst elmo-datevec-to-time (datevec) + (encode-time (aref datevec 5) (aref datevec 4) (aref datevec 3) + (aref datevec 2) (aref datevec 1) (aref datevec 0) + (aref datevec 6))) + +(defun elmo-time-parse-date-string (date) + (ignore-errors + (elmo-datevec-to-time (timezone-fix-time date nil nil)))) + +(defun elmo-time-make-date-string (time) + (let ((system-time-locale "C")) + (format-time-string "%a, %d %b %Y %T %z" time))) + +(defun elmo-time-less-p (lhs rhs) + (while (and (car lhs) (car rhs)) + (cond ((< (car lhs) (car rhs)) + (setq lhs nil)) + ((= (car lhs) (car rhs)) + (setq lhs (cdr lhs) + rhs (cdr rhs))) + (t + (setq rhs nil)))) + (not (null rhs))) + +(defalias 'elmo-time< 'elmo-time-less-p) + +(defun elmo-time-to-days (time) + (let ((date (decode-time time))) + (timezone-absolute-from-gregorian + (nth 4 date) (nth 3 date) (nth 5 date)))) + +;; from timezone-fix-time in `timezone.el' +(defun elmo-time-to-datevec (time &optional timezone) + (when time + (let* ((date (decode-time time)) + (year (nth 5 date)) + (month (nth 4 date)) + (day (nth 3 date)) + (hour (nth 2 date)) + (minute (nth 1 date)) + (second (nth 0 date)) + (local (nth 8 date)) + (timezone + (or timezone + (timezone-time-zone-from-absolute + (timezone-absolute-from-gregorian month day year) + (+ second (* 60 (+ minute (* 60 hour))))))) + (diff (- (timezone-zone-to-minute timezone) (/ local 60))) + (minute (+ minute diff)) + (hour-fix (floor minute 60))) + (setq hour (+ hour hour-fix)) + (setq minute (- minute (* 60 hour-fix))) + ;; HOUR may be larger than 24 or smaller than 0. + (cond ((<= 24 hour) ;24 -> 00 + (setq hour (- hour 24)) + (setq day (1+ day)) + (when (< (timezone-last-day-of-month month year) day) + (setq month (1+ month)) + (setq day 1) + (when (< 12 month) + (setq month 1) + (setq year (1+ year))))) + ((> 0 hour) + (setq hour (+ hour 24)) + (setq day (1- day)) + (when (> 1 day) + (setq month (1- month)) + (when (> 1 month) + (setq month 12) + (setq year (1- year))) + (setq day (timezone-last-day-of-month month year))))) + (vector year month day hour minute second timezone)))) (require 'product) (product-provide (provide 'elmo-date) (require 'elmo-version))