comparison lisp/calendar/appt.el @ 65840:df9b548f3218

(appt-time-regexp): New var. (appt-add, appt-make-list): Use it. (appt-convert-time): Clean up.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 04 Oct 2005 20:50:40 +0000
parents 18a818a2ee7c
children 5c09efcfc1d9 aa89c814f853
comparison
equal deleted inserted replaced
65839:8d9f98ffeae4 65840:df9b548f3218
193 MINUTES is the time in minutes of the appointment after midnight, and 193 MINUTES is the time in minutes of the appointment after midnight, and
194 STRING is the description of the appointment. 194 STRING is the description of the appointment.
195 FLAG, if non-nil, says that the element was made with `appt-add' 195 FLAG, if non-nil, says that the element was made with `appt-add'
196 so calling `appt-make-list' again should preserve it.") 196 so calling `appt-make-list' again should preserve it.")
197 197
198 (defconst appt-max-time 1439 198 (defconst appt-max-time (1- (* 24 60))
199 "11:59pm in minutes - number of minutes in a day minus 1.") 199 "11:59pm in minutes - number of minutes in a day minus 1.")
200 200
201 (defvar appt-mode-string nil 201 (defvar appt-mode-string nil
202 "String being displayed in the mode line saying you have an appointment. 202 "String being displayed in the mode line saying you have an appointment.
203 The actual string includes the amount of time till the appointment. 203 The actual string includes the amount of time till the appointment.
482 (when (< bottom-edge next-bottom-edge) 482 (when (< bottom-edge next-bottom-edge)
483 (setq bottom-edge next-bottom-edge 483 (setq bottom-edge next-bottom-edge
484 lowest-window w))))) 484 lowest-window w)))))
485 (select-window lowest-window))) 485 (select-window lowest-window)))
486 486
487 (defconst appt-time-regexp
488 "[0-9]?[0-9]\\(h\\([0-9][0-9]\\)?\\|[:.][0-9][0-9]\\)\\(am\\|pm\\)?")
489
487 ;;;###autoload 490 ;;;###autoload
488 (defun appt-add (new-appt-time new-appt-msg) 491 (defun appt-add (new-appt-time new-appt-msg)
489 "Add an appointment for today at NEW-APPT-TIME with message NEW-APPT-MSG. 492 "Add an appointment for today at NEW-APPT-TIME with message NEW-APPT-MSG.
490 The time should be in either 24 hour format or am/pm format." 493 The time should be in either 24 hour format or am/pm format."
491 (interactive "sTime (hh:mm[am/pm]): \nsMessage: ") 494 (interactive "sTime (hh:mm[am/pm]): \nsMessage: ")
492 (unless (string-match "[0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?" 495 (unless (string-match appt-time-regexp new-appt-time)
493 new-appt-time)
494 (error "Unacceptable time-string")) 496 (error "Unacceptable time-string"))
495 (let* ((appt-time-string (concat new-appt-time " " new-appt-msg)) 497 (let* ((appt-time-string (concat new-appt-time " " new-appt-msg))
496 (appt-time (list (appt-convert-time new-appt-time))) 498 (appt-time (list (appt-convert-time new-appt-time)))
497 (time-msg (list appt-time appt-time-string t))) 499 (time-msg (list appt-time appt-time-string t)))
498 (setq appt-time-msg-list (nconc appt-time-msg-list (list time-msg))) 500 (setq appt-time-msg-list (nconc appt-time-msg-list (list time-msg)))
575 ;; Parse the entries for today. 577 ;; Parse the entries for today.
576 (while (and entry-list 578 (while (and entry-list
577 (calendar-date-equal 579 (calendar-date-equal
578 (calendar-current-date) (car (car entry-list)))) 580 (calendar-current-date) (car (car entry-list))))
579 (let ((time-string (cadr (car entry-list)))) 581 (let ((time-string (cadr (car entry-list))))
580 (while (string-match 582 (while (string-match appt-time-regexp time-string)
581 "\\([0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?\\).*"
582 time-string)
583 (let* ((beg (match-beginning 0)) 583 (let* ((beg (match-beginning 0))
584 ;; Get just the time for this appointment. 584 ;; Get just the time for this appointment.
585 (only-time (match-string 1 time-string)) 585 (only-time (match-string 0 time-string))
586 ;; Find the end of this appointment 586 ;; Find the end of this appointment
587 ;; (the start of the next). 587 ;; (the start of the next).
588 (end (string-match 588 (end (string-match
589 "^[ \t]*[0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?" 589 (concat "\n[ \t]*" appt-time-regexp)
590 time-string 590 time-string
591 (match-end 0))) 591 (match-end 0)))
592 ;; Get the whole string for this appointment. 592 ;; Get the whole string for this appointment.
593 (appt-time-string 593 (appt-time-string
594 (substring time-string beg (if end (1- end))))) 594 (substring time-string beg (if end (1- end)))))
631 631
632 (defun appt-convert-time (time2conv) 632 (defun appt-convert-time (time2conv)
633 "Convert hour:min[am/pm] format to minutes from midnight. 633 "Convert hour:min[am/pm] format to minutes from midnight.
634 A period (.) can be used instead of a colon (:) to separate the 634 A period (.) can be used instead of a colon (:) to separate the
635 hour and minute parts." 635 hour and minute parts."
636 (let ((conv-time 0) 636 ;; Formats that should be accepted:
637 (hr 0) 637 ;; 10:00 10.00 10h00 10h 10am 10:00am 10.00am
638 (min 0)) 638 (let ((min (if (string-match "[h:.]\\([0-9][0-9]\\)" time2conv)
639 639 (string-to-number (match-string 1 time2conv))
640 (string-match "[:.]\\([0-9][0-9]\\)" time2conv) 640 0))
641 (setq min (string-to-number 641 (hr (if (string-match "[0-9]*[0-9]" time2conv)
642 (match-string 1 time2conv))) 642 (string-to-number (match-string 0 time2conv))
643 643 0)))
644 (string-match "[0-9]?[0-9][:.]" time2conv)
645 (setq hr (string-to-number
646 (match-string 0 time2conv)))
647 644
648 ;; convert the time appointment time into 24 hour time 645 ;; convert the time appointment time into 24 hour time
649
650 (cond ((and (string-match "pm" time2conv) (< hr 12)) 646 (cond ((and (string-match "pm" time2conv) (< hr 12))
651 (setq hr (+ 12 hr))) 647 (setq hr (+ 12 hr)))
652 ((and (string-match "am" time2conv) (= hr 12)) 648 ((and (string-match "am" time2conv) (= hr 12))
653 (setq hr 0))) 649 (setq hr 0)))
654 650
655 ;; convert the actual time 651 ;; convert the actual time into minutes.
656 ;; into minutes for comparison 652 (+ (* hr 60) min)))
657 ;; against the actual time.
658
659 (setq conv-time (+ (* hr 60) min))
660 conv-time))
661 653
662 654
663 (defun appt-update-list () 655 (defun appt-update-list ()
664 "If the current buffer is visiting the diary, update appointments. 656 "If the current buffer is visiting the diary, update appointments.
665 This function is intended for use with `write-file-functions'." 657 This function is intended for use with `write-file-functions'."
717 (appt-check t)))) 709 (appt-check t))))
718 710
719 711
720 (provide 'appt) 712 (provide 'appt)
721 713
722 ;;; arch-tag: bf5791c4-8921-499e-a26f-772b1788d347 714 ;; arch-tag: bf5791c4-8921-499e-a26f-772b1788d347
723 ;;; appt.el ends here 715 ;;; appt.el ends here