From: kakugawa@se.hiroshima-u.ac.jp (Hirotsugu Kakugawa)
Newsgroups: fj.editor.emacs
Subject: Re: How to change Date field, GMT to JST.
Date: 1 Oct 92 08:01:22 GMT
Distribution: fj
Organization: Software Engineering Lab., Faculty of Engineering, Hiroshima
	Univ., Japan.
In-reply-to: s91m801@kansai-u.ac.jp's message of 29 Sep 92 11:58:55 JST

$@9-EgBg3X$N3Q@n$H?=$7$^$9!#(J

In article <S91M801.92Sep29115855@ipckus.kansai-u.ac.jp> s91m801@kansai-u.ac.jp (Marone / Takashi Murase) writes:

   >$@#G#N#U#S$N(J article $@%P%C%U%!$G!"(JDate $@%U%#!<%k%I$N(J GMT$@I=<($r(J JST$@I=<($K(J
   >$@$9$k$K$O!"$I$&$7$?$iNI$$$N$G$7$g$&$+!)(J

$@;d$O!"<!$N%3!<%I$r;H$C$F$$$^$9!#(J

 [
  .emacs $@$K<!$N$b$N$r$$$l$F$*$$$F2<$5$$$M!#(J: 
	(setq gnus-Startup-hook
	      (function (lambda () 
			  (load "gnus-GMT->LOCAL")
			  (setq gnus-local-timezone "JST"))))
 ]

  *--*--*--*BEGIN*--*--*--*
;;
;;  gnus-GMT->LOCAL.el  by kakugawa@se.hiroshima-u.ac.jp
;;

(setq gnus-Article-prepare-hook 
      (function (lambda ()
		  (save-excursion
		    (goto-char (point-min))
		    (if (re-search-forward "^Date: ")
			(let (gmt-date ps pe)
			  (setq ps (point))
			  (end-of-line)
			  (setq pe (point))
			  (setq gmt-date (buffer-substring ps pe))
			  (delete-region ps pe)
			  (insert (gnus-GMT->LOCALTIME 
				   gmt-date +9 "JST"))))))))

(defun gnus-GMT->LOCALTIME (gmt-date diff-hour local-time-name)
  "Convert the string GMT-DATE represented in gmt to local time.  
DIFF-HOUR is time difference mesured in hour. For instance, +9 is used
for jst. Name of local time is LOCAL-TIME-NAME" 
  (let ((local-date gmt-date)
	month-table
	(month-table-non-leap
	 (vector '("Dec" 31) 
	         '("Jan" 31) '("Feb" 28) '("Mar" 31) '("Apr" 30)
		 '("May" 31) '("Jun" 30) '("Jul" 31) '("Aug" 31)
		 '("Sep" 30) '("Oct" 31) '("Nov" 30) '("Dec" 31)
		 '("Jan" 31)))
	(month-table-leap
	 (vector '("Dec" 31) 
	         '("Jan" 31) '("Feb" 29) '("Mar" 31) '("Apr" 30)
		 '("May" 31) '("Jun" 30) '("Jul" 31) '("Aug" 31)
		 '("Sep" 30) '("Oct" 31) '("Nov" 30) '("Dec" 31)
		 '("Jan" 31)))
	(month-inv-table
	 '(("JAN" . 1)("FEB" . 2)("MAR" . 3)
	   ("APR" . 4)("MAY" . 5)("JUN" . 6)
	   ("JUL" . 7)("AUG" . 8)("SEP" . 9)
	   ("OCT" . 10)("NOV" . 11)("DEC" . 12)))
	gmt-sec gmt-min gmt-hour gmt-day gmt-month gmt-year
        local-sec local-min local-hour local-day local-month local-year
	(local-off-day 0) (local-off-month 0) (local-off-year 0))
    ;; Can understand the following styles:
    ;; (1) 14 Apr 89 03:20:12 GMT
    ;; (2) Fri, 17 Mar 89 4:01:33 GMT
    (if (string-match
	 "\\([0-9]+\\) \\([^ ,]+\\) \\([0-9]+\\) \\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)" gmt-date)
	(progn
	  ;; read gmt year
	  (setq gmt-year 
		(string-to-int 
		 (substring gmt-date (match-beginning 3) (match-end 3))))
	  ;; read gmt month
	  (setq gmt-month
		(cdr
		 (assoc
		  (upcase (substring gmt-date 
				     (match-beginning 2) (match-end 2)))
		   month-inv-table)))
	  ;; read gmt day
	  (setq gmt-day
		(string-to-int	(substring gmt-date
					   (match-beginning 1) 
					   (match-end 1))))
	  ;; read gmt hour
	  (setq gmt-hour
		(string-to-int
		 (substring gmt-date (match-beginning 4) (match-end 4))))
	  ;; read gmt minite
	  (setq gmt-min
		(string-to-int
		 (substring gmt-date (match-beginning 5) (match-end 5))))
	  ;; read gmt second
	  (setq gmt-sec
		(string-to-int
		 (substring gmt-date (match-beginning 6) (match-end 6)))) 
	  ;; leap?
	  (if (or (and (zerop (% gmt-year 4))
		       (not (zerop (% gmt-year 100))))
		  (zerop (% gmt-year 400)))
	      (setq month-table month-table-leap)
	    (setq month-table month-table-non-leap))
	  ;;
	  ;; GMT -> localtime
	  ;; local sec, min 
	  (setq local-sec gmt-sec)
	  (setq local-min gmt-min)
          ;; local hour
	  (setq local-hour 
		(+ gmt-hour diff-hour))
	  (if (> local-hour 23)
	      (progn
		(setq local-hour (- local-hour 24))
		(setq local-off-day +1)))
	  (if (< local-hour 0)
	      (progn
		(setq local-hour (+ local-hour 24))
		(setq local-off-day -1)))
	  ;; local day
	  (setq local-day (+ gmt-day local-off-day))
	  (if (< local-day 1)
	      (progn
		(setq local-off-month -1)
		(setq local-day 
		      (cadr (aref month-table (- gmt-month 1))))))
	  (if (> local-day (cadr (aref month-table gmt-month)))
	      (progn
		(setq local-off-month +1)
		(setq local-day 1)))
	  ;; jst month
	  (setq local-month (+ gmt-month local-off-month))
	  (if (= local-month 0)
	      (progn
		(setq local-off-year -1)
		(setq local-month 12)))
	  (if (= local-month 13)
	      (progn
		(setq local-off-year +1)
		(setq local-month 1)))
	  ; year
	  (setq local-year (+ gmt-year local-off-year))
	  ;;
	  (setq local-date
		(format "%d %s %02d %02d:%02d:%02d %s"
			local-day 
			(car (aref month-table local-month))
			local-year 
			local-hour local-min local-sec
			local-time-name))))
    local-date))


  *--*--*--* END *--*--*--*

--
  **    $@3Q@nM5<!(J  kakugawa@se.hiroshima-u.ac.jp
 * *    $@9-EgBg3XBg3X1!9)3X8&5f2JGn;N2]Dx8e4|#1G/(J  $@%=%U%H%&%(%"9)3X8&5f<<(J
   * Fly! Fly!!
Newsgroups: fj.editor.emacs