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
8 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
34 (if (module-installed-p 'timezone)
38 (defvar elmo-date-descriptions
39 '((yesterday . [0 0 1])
42 (lastyear . [1 0 0])))
44 (defun elmo-date-get-description (datevec)
47 (car (rassq (aref datevec 1)
48 timezone-months-assoc))
51 (defun elmo-date-get-datevec (description)
53 ((not elmo-date-match)
54 (error "date match is not available"))
55 ((string-match "^[ \t]*\\([0-9]+\\)?[ \t]*\\([a-zA-Z]+\\)$" description)
58 (timezone-fix-time (current-time-string) (current-time-zone)
62 (if (match-beginning 1)
63 (elmo-match-string 1 description)
65 (suffix (downcase (elmo-match-string 2 description)))
67 (if (setq pair (assq (intern suffix) elmo-date-descriptions))
68 (elmo-datevec-substitute today (cdr pair))
69 (if (string= "daysago" suffix)
70 (elmo-date-get-offset-datevec today number)
71 (error "%s is not supported yet" suffix)))))
72 ((string-match "[0-9]+-[A-Za-z]+-[0-9]+" description)
74 (concat (elmo-replace-in-string description "-" " ") " 0:00")
77 (defun elmo-datevec-substitute (datevec1 datevec2)
78 (if (/= (aref datevec2 2) 0)
79 (elmo-date-get-offset-datevec datevec1 (aref datevec2 2))
80 (let ((year (- (aref datevec1 0) (aref datevec2 0)))
81 (month (- (aref datevec1 1) (aref datevec2 1)))
82 (timezone (current-time-zone)))
87 (format "%d %s %d 0:00 %s"
89 (car (rassq month timezone-months-assoc))
91 (cadr timezone)) nil nil))))
93 (defun elmo-date-get-week (year month mday)
94 (let ((wday (symbol-value (intern (format
95 "elmo-weekday-name-%s"
99 (setq days (- (+ (* y1 365) (/ y1 400) (/ y1 4)) (/ y1 100)))
102 (setq days (+ days (timezone-last-day-of-month p year)))
105 (setq days (+ days mday))
106 (aref wday (% days 7))))
108 (defun elmo-date-get-offset-datevec (datevec offset &optional time)
109 (let ((year (aref datevec 0))
110 (month (aref datevec 1))
111 (day (aref datevec 2))
112 (hour (aref datevec 3))
113 (minute (aref datevec 4))
114 (second (aref datevec 5))
115 (timezone (aref datevec 6))
119 (setq day-number (- (timezone-day-number month day year)
121 (while (<= day-number 0)
123 day-number (+ (timezone-day-number 12 31 year)
125 (while (> day-number (setq day-of-month
126 (timezone-last-day-of-month p year)))
127 (setq day-number (- day-number day-of-month))
130 (setq day day-number)
132 (format "%d %s %d %s %s"
134 (car (rassq month timezone-months-assoc))
137 (format "%d:%d:%d" hour minute second)
139 (cadr timezone)) nil nil)))
143 ;;; elmo-date.el ends here