X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=elmo%2Felmo-date.el;h=ea2f0e577f9575ef74de0c322bc1f97b9908433e;hb=158d76afcd9b25ea8369062dfc53984f2f1435fc;hp=7dd66bbf65cd3ffe7c093612b8a251188ddb7597;hpb=1e366a559be4aec4ad4d3cf3e954b8e62a20d2f3;p=elisp%2Fwanderlust.git diff --git a/elmo/elmo-date.el b/elmo/elmo-date.el index 7dd66bb..ea2f0e5 100644 --- a/elmo/elmo-date.el +++ b/elmo/elmo-date.el @@ -1,10 +1,9 @@ -;;; elmo-date.el -- Date processing module for ELMO. +;;; elmo-date.el --- Date processing module for ELMO. -;; Copyright 1998,1999,2000 Yuuichi Teranishi +;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi ;; Author: Yuuichi Teranishi ;; Keywords: mail, net news -;; Time-stamp: <00/03/14 19:38:44 teranisi> ;; This file is part of ELMO (Elisp Library for Message Orchestration). @@ -25,17 +24,74 @@ ;; ;;; Commentary: -;; +;; ;;; Code: -;; +;; (require 'path-util) -(if (module-installed-p 'timezone) - (require 'timezone)) +(require 'timezone) (require 'elmo-vars) +(defmacro elmo-match-substring (pos string from) + "Substring of POSth matched string of STRING." + (` (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))))) + +(defmacro elmo-match-buffer (pos) + "Substring POSth matched from the current buffer." + (` (buffer-substring-no-properties + (match-beginning (, pos)) (match-end (, pos))))) + +;; from subr.el +(defun elmo-replace-in-string (str regexp newtext &optional literal) + "Replace all matches in STR for REGEXP with NEWTEXT string. +And returns the new string. +Optional LITERAL non-nil means do a literal replacement. +Otherwise treat \\ in NEWTEXT string as special: + \\& means substitute original matched text, + \\N means substitute match for \(...\) number N, + \\\\ means insert one \\." + (let ((rtn-str "") + (start 0) + (special) + match prev-start) + (while (setq match (string-match regexp str start)) + (setq prev-start start + start (match-end 0) + rtn-str + (concat + rtn-str + (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))))) + newtext "")))))) + (concat rtn-str (substring str start)))) + (defvar elmo-date-descriptions '((yesterday . [0 0 1]) (lastweek . [0 0 7]) @@ -50,15 +106,15 @@ (aref datevec 0))) (defun elmo-date-get-datevec (description) - (cond + (cond ((not elmo-date-match) - (error "date match is not available")) + (error "Date match is not available")) ((string-match "^[ \t]*\\([0-9]+\\)?[ \t]*\\([a-zA-Z]+\\)$" description) - (let ((today + (let ((today (save-match-data (timezone-fix-time (current-time-string) (current-time-zone) nil))) - (number + (number (string-to-int (if (match-beginning 1) (elmo-match-string 1 description) @@ -71,9 +127,15 @@ (elmo-date-get-offset-datevec today number) (error "%s is not supported yet" suffix))))) ((string-match "[0-9]+-[A-Za-z]+-[0-9]+" description) - (timezone-fix-time - (concat (elmo-replace-in-string description "-" " ") " 0:00") - nil nil)))) + (timezone-fix-time + (concat (elmo-replace-in-string description "-" " ") " 0:0") + (current-time-zone) nil)) + ((string-match "\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\)" description) + (vector (string-to-number (match-string 1 description)) + (string-to-number (match-string 2 description)) + (string-to-number (match-string 3 description)) + 0 0 0 + (current-time-zone))))) (defun elmo-datevec-substitute (datevec1 datevec2) (if (/= (aref datevec2 2) 0) @@ -101,8 +163,7 @@ (setq p 1) (while (< p month) (setq days (+ days (timezone-last-day-of-month p year))) - (setq p (+ p 1)) - ) + (setq p (+ p 1))) (setq days (+ days mday)) (aref wday (% days 7)))) @@ -114,7 +175,7 @@ (minute (aref datevec 4)) (second (aref datevec 5)) (timezone (aref datevec 6)) - day-number p + day-number p day-of-month) (setq p 1) (setq day-number (- (timezone-day-number month day year) @@ -139,6 +200,18 @@ "0:00") (cadr timezone)) nil nil))) -(provide 'elmo-date) +(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))))) + +(require 'product) +(product-provide (provide 'elmo-date) (require 'elmo-version)) ;;; elmo-date.el ends here