1 ;;; elmo-date.el -- Date processing module for ELMO.
3 ;; Copyright 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
7 ;; Time-stamp: <00/03/14 19:38:44 teranisi>
9 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
35 (if (module-installed-p 'timezone)
39 (defvar elmo-date-descriptions
40 '((yesterday . [0 0 1])
43 (lastyear . [1 0 0])))
45 (defun elmo-date-get-description (datevec)
48 (car (rassq (aref datevec 1)
49 timezone-months-assoc))
52 (defun elmo-date-get-datevec (description)
54 ((not elmo-date-match)
55 (error "date match is not available"))
56 ((string-match "^[ \t]*\\([0-9]+\\)?[ \t]*\\([a-zA-Z]+\\)$" description)
59 (timezone-fix-time (current-time-string) (current-time-zone)
63 (if (match-beginning 1)
64 (elmo-match-string 1 description)
66 (suffix (downcase (elmo-match-string 2 description)))
68 (if (setq pair (assq (intern suffix) elmo-date-descriptions))
69 (elmo-datevec-substitute today (cdr pair))
70 (if (string= "daysago" suffix)
71 (elmo-date-get-offset-datevec today number)
72 (error "%s is not supported yet" suffix)))))
73 ((string-match "[0-9]+-[A-Za-z]+-[0-9]+" description)
75 (concat (elmo-replace-in-string description "-" " ") " 0:00")
78 (defun elmo-datevec-substitute (datevec1 datevec2)
79 (if (/= (aref datevec2 2) 0)
80 (elmo-date-get-offset-datevec datevec1 (aref datevec2 2))
81 (let ((year (- (aref datevec1 0) (aref datevec2 0)))
82 (month (- (aref datevec1 1) (aref datevec2 1)))
83 (timezone (current-time-zone)))
88 (format "%d %s %d 0:00 %s"
90 (car (rassq month timezone-months-assoc))
92 (cadr timezone)) nil nil))))
94 (defun elmo-date-get-week (year month mday)
95 (let ((wday (symbol-value (intern (format
96 "elmo-weekday-name-%s"
100 (setq days (- (+ (* y1 365) (/ y1 400) (/ y1 4)) (/ y1 100)))
103 (setq days (+ days (timezone-last-day-of-month p year)))
106 (setq days (+ days mday))
107 (aref wday (% days 7))))
109 (defun elmo-date-get-offset-datevec (datevec offset &optional time)
110 (let ((year (aref datevec 0))
111 (month (aref datevec 1))
112 (day (aref datevec 2))
113 (hour (aref datevec 3))
114 (minute (aref datevec 4))
115 (second (aref datevec 5))
116 (timezone (aref datevec 6))
120 (setq day-number (- (timezone-day-number month day year)
122 (while (<= day-number 0)
124 day-number (+ (timezone-day-number 12 31 year)
126 (while (> day-number (setq day-of-month
127 (timezone-last-day-of-month p year)))
128 (setq day-number (- day-number day-of-month))
131 (setq day day-number)
133 (format "%d %s %d %s %s"
135 (car (rassq month timezone-months-assoc))
138 (format "%d:%d:%d" hour minute second)
140 (cadr timezone)) nil nil)))
144 ;;; elmo-date.el ends here