1;; skk-gadget.el -- �¹��Ѵ��Τ���Υץ����
2;; Copyright (C) 1995, 1996, 1997, 1998, 1999
3;; Masahiko Sato <masahiko@kuis.kyoto-u.ac.jp>
4
5;; Author: Masahiko Sato <masahiko@kuis.kyoto-u.ac.jp>
6;; Maintainer: Murata Shuuichirou  <mrt@astec.co.jp>
7;;             Mikio Nakajima <minakaji@osaka.email.ne.jp>
8;; Version: $Id: skk-trial.el,v 1.2 2002/12/16 12:36:53 tatari Exp $
9;; Keywords: japanese
10;; Last Modified: $Date: 2002/12/16 12:36:53 $
11
12;; This file is part of SKK.
13
14;; SKK is free software; you can redistribute it and/or modify
15;; it under the terms of the GNU General Public License as published by
16;; the Free Software Foundation; either versions 2, or (at your option)
17;; any later version.
18
19;; SKK is distributed in the hope that it will be useful
20;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22;; GNU General Public License for more details.
23
24;; You should have received a copy of the GNU General Public License
25;; along with SKK, see the file COPYING.  If not, write to the Free
26;; Software Foundation Inc., 59 Temple Place - Suite 330, Boston,
27;; MA 02111-1307, USA.
28
29(defun skk-date (&optional and-time)
30  (let* ((str (current-time-string))
31	 (y (- (string-to-int (substring str 20 24)) 1988))
32	 (year (if skk-date-ad
33		   (j-num (substring str 20 24))
34		 (if (= y 1) "��" (j-num (int-to-string y)))))
35	 (mon (substring str 4 7))
36	 (month
37	  (j-num
38	   (cdr (assoc mon
39		       '(("Jan" . "1") ("Feb" . "2") ("Mar" . "3")
40			 ("Apr" . "4") ("May" . "5") ("Jun" . "6")
41			 ("Jul" . "7") ("Aug" . "8") ("Sep" . "9")
42			 ("Oct" . "10") ("Nov" . "11") ("Dec" . "12"))))))
43	 (day (j-num (substring str 8 10)))
44	 (dw (substring str 0 3))
45	 (day-of-week
46	  (cdr (assoc dw
47		      '(("Sun" . "��") ("Mon" . "��") ("Tue" . "��")
48			("Wed" . "��") ("Thu" . "��") ("Fri" . "��")
49			("Sat" . "��")))))
50	 )
51    (concat (if skk-date-ad "" "ʿ��") year "ǯ"
52	    month "��" day "��" "\(" day-of-week "\)"
53	    (if and-time
54		(let ((hour (substring str 11 13))
55		      (minute (substring str 14 16))
56		      (second (substring str 17 19)))
57		  (concat " " hour "��" minute "ʬ" second "��"))))))
58
59(defun j-clock (&optional kakutei-when-quit time-signal)
60  (interactive "*")
61  (let ((start (current-time-string))
62	(local-map (current-local-map))
63	finish mes)
64    (unwind-protect
65	(progn
66	  (use-local-map nil)
67	  (condition-case nil
68	      (let (case-fold-search
69		    inhibit-quit
70		    visible-bell)
71		(while (not quit-flag)
72		  (setq mes (skk-date t))
73		  (message (concat  mes "    Hit any key to quit"))
74		  (unless (sit-for 1)
75		    (read-event)
76		    (signal 'quit nil))))
77	    (quit
78	     (prog2
79		 (setq finish (current-time-string))
80		 (skk-date t)
81	       ;;(skk-use-local-map skk-map)
82	       (if kakutei-when-quit
83		   (setq skk-kakutei-flag t) )
84	       (message (concat "���� :" (j-time-diff start finish)))))))
85      (progn
86	(use-local-map local-map)))))
87
88(defun j-time-diff (start finish)
89  ;; (current-time-string) ���֤��� START �� FINISH �λ��ֺ����ᡢ
90  ;; "����:ʬ:��" �η������֤���skk-clock �Υ��֥롼����
91  (let ((s-hour (string-to-int (substring start 11 13)))
92        (s-minute (string-to-int (substring start 14 16)))
93        (s-second (string-to-int (substring start 17 19)))
94        (f-hour (string-to-int (substring finish 11 13)))
95        (f-minute (string-to-int (substring finish 14 16)))
96        (f-second (string-to-int (substring finish 17 19)))
97        second-diff minute-diff hour-diff )
98    (if (not (string= (substring start 20) (substring finish 20)))
99        (error "�㤦ǯ�λ��ֺ��Ϸ׻��Ǥ��ޤ���"))
100    (setq second-diff (- f-second s-second))
101    (if (> 0 second-diff)
102        (setq f-minute (1- f-minute)
103              second-diff (- (+ f-second 60) s-second) ))
104    (setq minute-diff (- f-minute s-minute))
105    (if (> 0 minute-diff)
106        (setq f-hour (1- f-hour)
107              minute-diff (- (+ f-minute 60) s-minute) ))
108    (setq hour-diff (- f-hour s-hour))
109    (if (> 0 hour-diff)
110        (error "�裲�������裱��������λ��֤Ǥʤ���Фʤ�ޤ���"))
111    (format "%02d:%02d:%02d" hour-diff minute-diff second-diff) ))
112
113