;;; ;;; time-table.el: time recorder. ;;; ;;; Jan.20,'96. neco. ;;; [1996/10/22] OSHIRO Naoki. ;;; ・diff-time-string-.. を時間だけでなく日付も考慮するようにした. ;;; 関数名は diff-date-string-.. とした.但し,月の変わり目は考慮 ;;; しない. ;;; ;;; $Log:$ ;;; (require 'get-date) (defvar time-table-file (expand-file-name (if (eq system-type 'ms-dos) "~/timetabh.txt" "~/kenkyu/TimeTable"))) (defvar time-table-format "%4d/%2d/%2d %2d:%2d") (defun time-table () (interactive) (let (time (start 0) (end 0)) (find-file time-table-file) ; (end-of-buffer) (goto-char (point-max)) (insert (concat (get-dtime) "\n" )) (re-search-backward "^.+[0-9][0-9]:[0-9][0-9]") (re-search-backward "^.+[0-9][0-9]:[0-9][0-9]") ; (setq time (diff-time-string-of-two-lines)) (setq time (diff-date-string-of-two-lines)) (end-of-line) (save-excursion (insert (concat "[" time "]"))))) (defun diff-time-string-of-two-lines () (interactive) (let (time start end) (save-excursion (if (search-forward-time-string) (setq start (time-string-to-int (buffer-substring (match-beginning 0) (match-end 0))))) (forward-line 1) (beginning-of-line) (if (search-forward-time-string) (setq end (time-string-to-int (buffer-substring (match-beginning 0) (match-end 0))))) (setq time (int-to-time-string (- end start)))) (if (interactive-p) (progn (end-of-line) (insert (concat "[" time "]"))) time) )) (defun diff-date-string-of-two-lines () (interactive) (let (time start end) (save-excursion (if (re-search-forward "[0-9][0-9]/[0-9][0-9] [0-9][0-9]:[0-9][0-9]") (setq start (buffer-substring (match-beginning 0) (match-end 0)))) (forward-line 1) (beginning-of-line) (if (re-search-forward "[0-9][0-9]/[0-9][0-9] [0-9][0-9]:[0-9][0-9]") (setq end (buffer-substring (match-beginning 0) (match-end 0)))) (setq time (int-to-time-string (date-to-time-string end start)))) (if (interactive-p) (progn (end-of-line) (insert (concat "[" time "]"))) time) )) (defun time-string-to-int (str) (let ((hour (string-to-int (substring str 0 2))) (min (string-to-int (substring str 3 5)))) (+ (* hour 60) min))) (defun subint (str from to) (string-to-int (substring str from to))) (defun date-to-time-string (to org) (let ((t-mon (subint to 0 2)) (t-day (subint to 3 5)) (t-hour (subint to 6 8)) (t-min (subint to 9 11)) (o-mon (subint org 0 2)) (o-day (subint org 3 5)) (o-hour (subint org 6 8)) (o-min (subint org 9 11))) (- (+ (* (+ (* (- t-day o-day) 24) t-hour) 60) t-min) (+ (* o-hour 60) o-min)))) (defun int-to-time-string (sec) (let (hour min) (setq hour (string-to-int (format "%d" (/ sec 60)))) (setq min (mod sec 60)) (format "%02d:%02d" hour min))) (provide 'time-table) ;;; end of time-table here