summaryrefslogtreecommitdiffstats
path: root/ymh-emacs/ymh-diary.el
blob: c0262926ec2b379c035f5dfbe61abf6afc6f7ab2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
;;; ymh-diary.el --- Extensions to the Emacs Diary  -*- lexical-binding: t; -*-

;;; Commentary:

;; This file contains extensions to the built-in Emacs Diary.  Mainly, it adds a
;; timezone conversion to the diary display function, so that if

;;; Code:

(defun ymh-diary-schedule (y1 m1 d1 y2 m2 d2 dayname &optional mark)
  "Entry applies if date is between dates on DAYNAME.
    Order of the parameters is M1, D1, Y1, M2, D2, Y2 if
    `european-calendar-style' is nil, and D1, M1, Y1, D2, M2, Y2 if
    `european-calendar-style' is t. Entry does not apply on a history."
  (with-no-warnings (defvar date) (defvar entry))
  (let ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
        (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
        (d (calendar-absolute-from-gregorian date)))
    (if (and
         (<= date1 d)
         (<= d date2)
         (= (calendar-day-of-week date) dayname)
         ;;(not (calendar-check-holidays date))
         )
        (cons mark entry))))

(defun ymh-diary-last-day-of-month (date)
  "Return `t` if DATE is the last day of the month."
  (let* ((day (calendar-extract-day date))
         (month (calendar-extract-month date))
         (year (calendar-extract-year date))
         (last-day-of-month
          (calendar-last-day-of-month month year)))
    (= day last-day-of-month)))

(defun ymh-diary-org-export-to-ics ()
  "Export diary file to ICal format."
  (with-temp-buffer
    (insert-file-contents diary-file)
    (setq ics-file-body (org-diary-to-ical-string (current-buffer))))
  (with-temp-file "~/Downloads/emacs.ics"
    (insert "BEGIN:VCALENDAR
PRODID:-//E-DIARY//E-DIARY 1.0//EN
VERSION:2.0
METHOD:PUBLISH
X-WR-CALNAME:Emacs
X-Built-On-Cache-Miss:true
" ics-file-body "END:VCALENDAR")))

(defun ymh-diary-export-to-ics ()
  "Export the current diary to ICS format."
  (interactive)
  (icalendar-export-file
   diary-file
   (expand-file-name "emacs.ics" "~/Downloads")))

(provide 'ymh-diary)

;;; ymh-diary.el ends here