annotate lisp/calendar/icalendar.el @ 63348:abe4cbe0bdef

(NEWOPENFILENAME): New struct. (Fx_file_dialog): Use it to trick the system into giving us up to date dialogs on systems that are documented to support it. Do not set OFN_FILEMUSTEXIST flag if looking for a directory.
author Jason Rumney <jasonr@gnu.org>
date Sun, 12 Jun 2005 19:22:40 +0000
parents 6812f1044f86
children 18a818a2ee7c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1 ;;; icalendar.el --- iCalendar implementation -*-coding: utf-8 -*-
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
2
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
3 ;; Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
4
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
5 ;; Author: Ulf Jasper <ulf.jasper@web.de>
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
6 ;; Created: August 2002
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
7 ;; Keywords: calendar
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
8 ;; Human-Keywords: calendar, diary, iCalendar, vCalendar
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
9
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
11
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
15 ;; any later version.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
16
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
21
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29 ;; This package is documented in the Emacs Manual.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
31 ;; Please note:
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
32 ;; - Diary entries which have a start time but no end time are assumed to
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
33 ;; last for one hour when they are exported.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
34 ;; - Weekly diary entries are assumed to occur the first time in the first
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
35 ;; week of the year 2000 when they are exported.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
36 ;; - Yearly diary entries are assumed to occur the first time in the year
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
37 ;; 1900 when they are exported.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
38
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 ;;; History:
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
41 ;; 0.07 onwards: see lisp/ChangeLog
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
42
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
43 ;; 0.06: Bugfixes regarding icalendar-import-format-*.
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
44 ;; Fix in icalendar-convert-diary-to-ical -- thanks to Philipp
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
45 ;; Grau.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 ;; 0.05: New import format scheme: Replaced icalendar-import-prefix-*,
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 ;; icalendar-import-ignored-properties, and
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 ;; icalendar-import-separator with icalendar-import-format(-*).
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 ;; icalendar-import-file and icalendar-convert-diary-to-ical
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51 ;; have an extra parameter which should prevent them from
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52 ;; erasing their target files (untested!).
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 ;; Tested with Emacs 21.3.2
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 ;; 0.04: Bugfix: import: double quoted param values did not work
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 ;; Read DURATION property when importing.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 ;; Added parameter icalendar-duration-correction.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59 ;; 0.03: Export takes care of european-calendar-style.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 ;; Tested with Emacs 21.3.2 and XEmacs 21.4.12
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62 ;; 0.02: Should work in XEmacs now. Thanks to Len Trigg for the
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63 ;; XEmacs patches!
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64 ;; Added exporting from Emacs diary to ical.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 ;; Some bugfixes, after testing with calendars from
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 ;; http://icalshare.com.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67 ;; Tested with Emacs 21.3.2 and XEmacs 21.4.12
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 ;; 0.01: First published version. Trial version. Alpha version.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72 ;; To Do:
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
74 ;; * Import from ical to diary:
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 ;; + Need more properties for icalendar-import-format
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76 ;; + check vcalendar version
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77 ;; + check (unknown) elements
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78 ;; + recurring events!
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79 ;; + works for european style calendars only! Does it?
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80 ;; + alarm
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81 ;; + exceptions in recurring events
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82 ;; + the parser is too soft
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83 ;; + error log is incomplete
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
84 ;; + nice to have: #include "webcal://foo.com/some-calendar.ics"
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
85 ;; + timezones, currently all times are local!
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
86
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
87 ;; * Export from diary to ical
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
88 ;; + diary-date, diary-float, and self-made sexp entries are not
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
89 ;; understood
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
90
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
91 ;; * Other things
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
92 ;; + clean up all those date/time parsing functions
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
93 ;; + Handle todo items?
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
94 ;; + Check iso 8601 for datetime and period
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
95 ;; + Which chars to (un)escape?
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
96
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
97
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
98 ;;; Code:
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
99
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
100 (defconst icalendar-version 0.12
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
101 "Version number of icalendar.el.")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
102
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
103 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
104 ;; Customizables
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
105 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
106 (defgroup icalendar nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
107 "Icalendar support."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
108 :prefix "icalendar-"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
109 :group 'calendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
110
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
111 (defcustom icalendar-import-format
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
112 "%s%d%l%o"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
113 "Format string for importing events from iCalendar into Emacs diary.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
114 This string defines how iCalendar events are inserted into diary
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
115 file. Meaning of the specifiers:
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
116 %d Description, see `icalendar-import-format-description'
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
117 %l Location, see `icalendar-import-format-location'
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
118 %o Organizer, see `icalendar-import-format-organizer'
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
119 %s Subject, see `icalendar-import-format-subject'"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
120 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
121 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
122
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
123 (defcustom icalendar-import-format-subject
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
124 "%s"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
125 "Format string defining how the subject element is formatted.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
126 This applies only if the subject is not empty! `%s' is replaced
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
127 by the subject."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
128 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
129 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
130
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
131 (defcustom icalendar-import-format-description
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
132 "\n Desc: %s"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
133 "Format string defining how the description element is formatted.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
134 This applies only if the description is not empty! `%s' is
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
135 replaced by the description."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
136 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
137 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
138
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
139 (defcustom icalendar-import-format-location
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
140 "\n Location: %s"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
141 "Format string defining how the location element is formatted.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
142 This applies only if the location is not empty! `%s' is replaced
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
143 by the location."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
144 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
145 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
146
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
147 (defcustom icalendar-import-format-organizer
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
148 "\n Organizer: %s"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
149 "Format string defining how the organizer element is formatted.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
150 This applies only if the organizer is not empty! `%s' is
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
151 replaced by the organizer."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
152 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
153 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
154
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
155 (defvar icalendar-debug nil
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
156 "Enable icalendar debug messages.")
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
157
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
158 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
159 ;; NO USER SERVICABLE PARTS BELOW THIS LINE
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
160 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
161
57652
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
162 (defconst icalendar--weekday-array ["SU" "MO" "TU" "WE" "TH" "FR" "SA"])
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
163
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
164 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
165 ;; all the other libs we need
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
166 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
167 (require 'calendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
168
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
169 ;; ======================================================================
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
170 ;; misc
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
171 ;; ======================================================================
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
172 (defun icalendar--dmsg (&rest args)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
173 "Print message ARGS if `icalendar-debug' is non-nil."
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
174 (if icalendar-debug
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
175 (apply 'message args)))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
176
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
177 ;; ======================================================================
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
178 ;; Core functionality
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
179 ;; Functions for parsing icalendars, importing and so on
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
180 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
181
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
182 (defun icalendar--get-unfolded-buffer (folded-ical-buffer)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
183 "Return a new buffer containing the unfolded contents of a buffer.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
184 Folding is the iCalendar way of wrapping long lines. In the
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
185 created buffer all occurrences of CR LF BLANK are replaced by the
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
186 empty string. Argument FOLDED-ICAL-BUFFER is the unfolded input
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
187 buffer."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
188 (let ((unfolded-buffer (get-buffer-create " *icalendar-work*")))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
189 (save-current-buffer
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
190 (set-buffer unfolded-buffer)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
191 (erase-buffer)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
192 (insert-buffer folded-ical-buffer)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
193 (while (re-search-forward "\r?\n[ \t]" nil t)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
194 (replace-match "" nil nil)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
195 unfolded-buffer))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
196
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
197 (defsubst icalendar--rris (re rp st)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
198 "Replace regexp RE with RP in string ST and return the new string.
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
199 This is here for compatibility with XEmacs."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
200 ;; XEmacs:
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
201 (if (fboundp 'replace-in-string)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
202 (save-match-data ;; apparently XEmacs needs save-match-data
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
203 (replace-in-string st re rp))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
204 ;; Emacs:
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
205 (replace-regexp-in-string re rp st)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
206
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
207 (defun icalendar--read-element (invalue inparams)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
208 "Recursively read the next iCalendar element in the current buffer.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
209 INVALUE gives the current iCalendar element we are reading.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
210 INPARAMS gives the current parameters.....
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
211 This function calls itself recursively for each nested calendar element
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
212 it finds"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
213 (let (element children line name params param param-name param-value
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
214 value
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
215 (continue t))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
216 (setq children '())
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
217 (while (and continue
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
218 (re-search-forward "^\\([A-Za-z0-9-]+\\)[;:]" nil t))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
219 (setq name (intern (match-string 1)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
220 (backward-char 1)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
221 (setq params '())
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
222 (setq line '())
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
223 (while (looking-at ";")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
224 (re-search-forward ";\\([A-Za-z0-9-]+\\)=" nil nil)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
225 (setq param-name (intern (match-string 1)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
226 (re-search-forward "\\(\\([^;,:\"]+\\)\\|\"\\([^\"]+\\)\"\\)[;:]"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
227 nil t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
228 (backward-char 1)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
229 (setq param-value (or (match-string 2) (match-string 3)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
230 (setq param (list param-name param-value))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
231 (while (looking-at ",")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
232 (re-search-forward "\\(\\([^;,:]+\\)\\|\"\\([^\"]+\\)\"\\)"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
233 nil t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
234 (if (match-string 2)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
235 (setq param-value (match-string 2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
236 (setq param-value (match-string 3)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
237 (setq param (append param param-value)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
238 (setq params (append params param)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
239 (unless (looking-at ":")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
240 (error "Oops"))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
241 (forward-char 1)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
242 (re-search-forward "\\(.*\\)\\(\r?\n[ \t].*\\)*" nil t)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
243 (setq value (icalendar--rris "\r?\n[ \t]" "" (match-string 0)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
244 (setq line (list name params value))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
245 (cond ((eq name 'BEGIN)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
246 (setq children
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
247 (append children
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
248 (list (icalendar--read-element (intern value)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
249 params)))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
250 ((eq name 'END)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
251 (setq continue nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
252 (t
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
253 (setq element (append element (list line))))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
254 (if invalue
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
255 (list invalue inparams element children)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
256 children)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
257
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
258 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
259 ;; helper functions for examining events
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
260 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
261
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
262 ;;(defsubst icalendar--get-all-event-properties (event)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
263 ;; "Return the list of properties in this EVENT."
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
264 ;; (car (cddr event)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
265
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
266 (defun icalendar--get-event-property (event prop)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
267 "For the given EVENT return the value of the first occurence of PROP."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
268 (catch 'found
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
269 (let ((props (car (cddr event))) pp)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
270 (while props
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
271 (setq pp (car props))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
272 (if (eq (car pp) prop)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
273 (throw 'found (car (cddr pp))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
274 (setq props (cdr props))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
275 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
276
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
277 (defun icalendar--get-event-property-attributes (event prop)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
278 "For the given EVENT return attributes of the first occurence of PROP."
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
279 (catch 'found
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
280 (let ((props (car (cddr event))) pp)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
281 (while props
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
282 (setq pp (car props))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
283 (if (eq (car pp) prop)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
284 (throw 'found (cadr pp)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
285 (setq props (cdr props))))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
286 nil))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
287
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
288 (defun icalendar--get-event-properties (event prop)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
289 "For the given EVENT return a list of all values of the property PROP."
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
290 (let ((props (car (cddr event))) pp result)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
291 (while props
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
292 (setq pp (car props))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
293 (if (eq (car pp) prop)
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
294 (setq result (append (split-string (car (cddr pp)) ",") result)))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
295 (setq props (cdr props)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
296 result))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
297
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
298 ;; (defun icalendar--set-event-property (event prop new-value)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
299 ;; "For the given EVENT set the property PROP to the value NEW-VALUE."
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
300 ;; (catch 'found
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
301 ;; (let ((props (car (cddr event))) pp)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
302 ;; (while props
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
303 ;; (setq pp (car props))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
304 ;; (when (eq (car pp) prop)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
305 ;; (setcdr (cdr pp) new-value)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
306 ;; (throw 'found (car (cddr pp))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
307 ;; (setq props (cdr props)))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
308 ;; (setq props (car (cddr event)))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
309 ;; (setcar (cddr event)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
310 ;; (append props (list (list prop nil new-value)))))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
311
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
312 (defun icalendar--get-children (node name)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
313 "Return all children of the given NODE which have a name NAME.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
314 For instance the VCALENDAR node can have VEVENT children as well as VTODO
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
315 children."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
316 (let ((result nil)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
317 (children (cadr (cddr node))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
318 (when (eq (car node) name)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
319 (setq result node))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
320 ;;(message "%s" node)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
321 (when children
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
322 (let ((subresult
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
323 (delq nil
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
324 (mapcar (lambda (n)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
325 (icalendar--get-children n name))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
326 children))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
327 (if subresult
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
328 (if result
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
329 (setq result (append result subresult))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
330 (setq result subresult)))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
331 result))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
332
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
333 ; private
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
334 (defun icalendar--all-events (icalendar)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
335 "Return the list of all existing events in the given ICALENDAR."
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
336 (icalendar--get-children (car icalendar) 'VEVENT))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
337
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
338 (defun icalendar--split-value (value-string)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
339 "Split VALUE-STRING at ';='."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
340 (let ((result '())
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
341 param-name param-value)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
342 (when value-string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
343 (save-current-buffer
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
344 (set-buffer (get-buffer-create " *icalendar-work*"))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
345 (set-buffer-modified-p nil)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
346 (erase-buffer)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
347 (insert value-string)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
348 (goto-char (point-min))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
349 (while
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
350 (re-search-forward
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
351 "\\([A-Za-z0-9-]+\\)=\\(\\([^;,:]+\\)\\|\"\\([^\"]+\\)\"\\);?"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
352 nil t)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
353 (setq param-name (intern (match-string 1)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
354 (setq param-value (match-string 2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
355 (setq result
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
356 (append result (list (list param-name param-value)))))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
357 result))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
358
60235
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
359 (defun icalendar--decode-isodatetime (isodatetimestring &optional day-shift)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
360 "Return ISODATETIMESTRING in format like `decode-time'.
60235
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
361 Converts from ISO-8601 to Emacs representation. If
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
362 ISODATETIMESTRING specifies UTC time (trailing letter Z) the
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
363 decoded time is given in the local time zone! If optional
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
364 parameter DAY-SHIFT is non-nil the result is shifted by DAY-SHIFT
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
365 days.
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
366
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
367 FIXME: TZID-attributes are ignored....!
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
368 FIXME: multiple comma-separated values should be allowed!"
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
369 (icalendar--dmsg isodatetimestring)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
370 (if isodatetimestring
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
371 ;; day/month/year must be present
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
372 (let ((year (read (substring isodatetimestring 0 4)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
373 (month (read (substring isodatetimestring 4 6)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
374 (day (read (substring isodatetimestring 6 8)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
375 (hour 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
376 (minute 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
377 (second 0))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
378 (when (> (length isodatetimestring) 12)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
379 ;; hour/minute present
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
380 (setq hour (read (substring isodatetimestring 9 11)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
381 (setq minute (read (substring isodatetimestring 11 13))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
382 (when (> (length isodatetimestring) 14)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
383 ;; seconds present
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
384 (setq second (read (substring isodatetimestring 13 15))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
385 (when (and (> (length isodatetimestring) 15)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
386 ;; UTC specifier present
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
387 (char-equal ?Z (aref isodatetimestring 15)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
388 ;; if not UTC add current-time-zone offset
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
389 (setq second (+ (car (current-time-zone)) second)))
60235
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
390 ;; shift if necessary
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
391 (if day-shift
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
392 (let ((mdy (calendar-gregorian-from-absolute
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
393 (+ (calendar-absolute-from-gregorian
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
394 (list month day year))
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
395 day-shift))))
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
396 (setq month (nth 0 mdy))
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
397 (setq day (nth 1 mdy))
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
398 (setq year (nth 2 mdy))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
399 ;; create the decoded date-time
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
400 ;; FIXME!?!
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
401 (condition-case nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
402 (decode-time (encode-time second minute hour day month year))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
403 (error
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
404 (message "Cannot decode \"%s\"" isodatetimestring)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
405 ;; hope for the best...
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
406 (list second minute hour day month year 0 nil 0))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
407 ;; isodatetimestring == nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
408 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
409
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
410 (defun icalendar--decode-isoduration (isodurationstring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
411 &optional duration-correction)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
412 "Convert ISODURATIONSTRING into format provided by `decode-time'.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
413 Converts from ISO-8601 to Emacs representation. If ISODURATIONSTRING
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
414 specifies UTC time (trailing letter Z) the decoded time is given in
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
415 the local time zone!
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
416
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
417 Optional argument DURATION-CORRECTION shortens result by one day.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
418
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
419 FIXME: TZID-attributes are ignored....!
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
420 FIXME: multiple comma-separated values should be allowed!"
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
421 (if isodurationstring
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
422 (save-match-data
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
423 (string-match
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
424 (concat
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
425 "^P[+-]?\\("
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
426 "\\(\\([0-9]+\\)D\\)" ; days only
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
427 "\\|"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
428 "\\(\\(\\([0-9]+\\)D\\)?T\\(\\([0-9]+\\)H\\)?" ; opt days
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
429 "\\(\\([0-9]+\\)M\\)?\\(\\([0-9]+\\)S\\)?\\)" ; mand. time
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
430 "\\|"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
431 "\\(\\([0-9]+\\)W\\)" ; weeks only
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
432 "\\)$") isodurationstring)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
433 (let ((seconds 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
434 (minutes 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
435 (hours 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
436 (days 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
437 (months 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
438 (years 0))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
439 (cond
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
440 ((match-beginning 2) ;days only
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
441 (setq days (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
442 (match-beginning 3)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
443 (match-end 3))))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
444 (when duration-correction
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
445 (setq days (1- days))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
446 ((match-beginning 4) ;days and time
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
447 (if (match-beginning 5)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
448 (setq days (* 7 (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
449 (match-beginning 6)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
450 (match-end 6))))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
451 (if (match-beginning 7)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
452 (setq hours (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
453 (match-beginning 8)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
454 (match-end 8)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
455 (if (match-beginning 9)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
456 (setq minutes (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
457 (match-beginning 10)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
458 (match-end 10)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
459 (if (match-beginning 11)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
460 (setq seconds (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
461 (match-beginning 12)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
462 (match-end 12))))))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
463 ((match-beginning 13) ;weeks only
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
464 (setq days (* 7 (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
465 (match-beginning 14)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
466 (match-end 14)))))))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
467 (list seconds minutes hours days months years)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
468 ;; isodatetimestring == nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
469 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
470
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
471 (defun icalendar--add-decoded-times (time1 time2)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
472 "Add TIME1 to TIME2.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
473 Both times must be given in decoded form. One of these times must be
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
474 valid (year > 1900 or something)."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
475 ;; FIXME: does this function exist already?
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
476 (decode-time (encode-time
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
477 (+ (nth 0 time1) (nth 0 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
478 (+ (nth 1 time1) (nth 1 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
479 (+ (nth 2 time1) (nth 2 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
480 (+ (nth 3 time1) (nth 3 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
481 (+ (nth 4 time1) (nth 4 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
482 (+ (nth 5 time1) (nth 5 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
483 nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
484 nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
485 ;;(or (nth 6 time1) (nth 6 time2)) ;; FIXME?
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
486 )))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
487
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
488 (defun icalendar--datetime-to-noneuropean-date (datetime &optional separator)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
489 "Convert the decoded DATETIME to non-european-style format.
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
490 Optional argument SEPARATOR gives the separator between month,
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
491 day, and year. If nil a blank character is used as separator.
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
492 Non-European format: \"month day year\"."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
493 (if datetime
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
494 (format "%d%s%d%s%d" (nth 4 datetime) ;month
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
495 (or separator " ")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
496 (nth 3 datetime) ;day
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
497 (or separator " ")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
498 (nth 5 datetime)) ;year
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
499 ;; datetime == nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
500 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
501
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
502 (defun icalendar--datetime-to-european-date (datetime &optional separator)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
503 "Convert the decoded DATETIME to European format.
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
504 Optional argument SEPARATOR gives the separator between month,
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
505 day, and year. If nil a blank character is used as separator.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
506 European format: (day month year).
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
507 FIXME"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
508 (if datetime
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
509 (format "%d%s%d%s%d" (nth 3 datetime) ;day
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
510 (or separator " ")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
511 (nth 4 datetime) ;month
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
512 (or separator " ")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
513 (nth 5 datetime)) ;year
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
514 ;; datetime == nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
515 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
516
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
517 (defun icalendar--datetime-to-diary-date (datetime &optional separator)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
518 "Convert the decoded DATETIME to diary format.
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
519 Optional argument SEPARATOR gives the separator between month,
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
520 day, and year. If nil a blank character is used as separator.
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
521 Call icalendar--datetime-to-(non)-european-date according to
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
522 value of `european-calendar-style'."
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
523 (if european-calendar-style
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
524 (icalendar--datetime-to-european-date datetime separator)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
525 (icalendar--datetime-to-noneuropean-date datetime separator)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
526
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
527 (defun icalendar--datetime-to-colontime (datetime)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
528 "Extract the time part of a decoded DATETIME into 24-hour format.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
529 Note that this silently ignores seconds."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
530 (format "%02d:%02d" (nth 2 datetime) (nth 1 datetime)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
531
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
532 (defun icalendar--get-month-number (monthname)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
533 "Return the month number for the given MONTHNAME."
57652
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
534 (catch 'found
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
535 (let ((num 1)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
536 (m (downcase monthname)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
537 (mapc (lambda (month)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
538 (let ((mm (downcase month)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
539 (if (or (string-equal mm m)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
540 (string-equal (substring mm 0 3) m))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
541 (throw 'found num))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
542 (setq num (1+ num))))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
543 calendar-month-name-array))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
544 ;; Error:
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
545 -1))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
546
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
547 (defun icalendar--get-weekday-number (abbrevweekday)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
548 "Return the number for the ABBREVWEEKDAY."
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
549 (if abbrevweekday
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
550 (catch 'found
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
551 (let ((num 0)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
552 (aw (downcase abbrevweekday)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
553 (mapc (lambda (day)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
554 (let ((d (downcase day)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
555 (if (string-equal d aw)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
556 (throw 'found num))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
557 (setq num (1+ num))))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
558 icalendar--weekday-array)))
57652
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
559 ;; Error:
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
560 -1))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
561
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
562 (defun icalendar--get-weekday-abbrev (weekday)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
563 "Return the abbreviated WEEKDAY."
57652
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
564 (catch 'found
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
565 (let ((num 0)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
566 (w (downcase weekday)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
567 (mapc (lambda (day)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
568 (let ((d (downcase day)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
569 (if (or (string-equal d w)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
570 (string-equal (substring d 0 3) w))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
571 (throw 'found (aref icalendar--weekday-array num)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
572 (setq num (1+ num))))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
573 calendar-day-name-array))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
574 ;; Error:
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
575 nil))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
576
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
577 (defun icalendar--date-to-isodate (date &optional day-shift)
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
578 "Convert DATE to iso-style date.
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
579 DATE must be a list of the form (month day year).
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
580 If DAY-SHIFT is non-nil, the result is shifted by DAY-SHIFT days."
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
581 (let ((mdy (calendar-gregorian-from-absolute
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
582 (+ (calendar-absolute-from-gregorian date)
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
583 (or day-shift 0)))))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
584 (format "%04d%02d%02d" (nth 2 mdy) (nth 0 mdy) (nth 1 mdy))))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
585
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
586
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
587 (defun icalendar--datestring-to-isodate (datestring &optional day-shift)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
588 "Convert diary-style DATESTRING to iso-style date.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
589 If DAY-SHIFT is non-nil, the result is shifted by DAY-SHIFT days
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
590 -- DAY-SHIFT must be either nil or an integer. This function
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
591 takes care of european-style."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
592 (let ((day -1) month year)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
593 (save-match-data
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
594 (cond ( ;; numeric date
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
595 (string-match (concat "\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
596 "0?\\([1-9][0-9]?\\)[ \t/]\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
597 "0?\\([1-9][0-9]?\\),?[ \t/]\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
598 "\\([0-9]\\{4\\}\\)")
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
599 datestring)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
600 (setq day (read (substring datestring (match-beginning 1)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
601 (match-end 1))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
602 (setq month (read (substring datestring (match-beginning 2)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
603 (match-end 2))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
604 (setq year (read (substring datestring (match-beginning 3)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
605 (match-end 3))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
606 (unless european-calendar-style
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
607 (let ((x month))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
608 (setq month day)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
609 (setq day x))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
610 ( ;; date contains month names -- european-style
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
611 (and european-calendar-style
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
612 (string-match (concat "\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
613 "0?\\([123]?[0-9]\\)[ \t/]\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
614 "\\([A-Za-z][^ ]+\\)[ \t/]\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
615 "\\([0-9]\\{4\\}\\)")
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
616 datestring))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
617 (setq day (read (substring datestring (match-beginning 1)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
618 (match-end 1))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
619 (setq month (icalendar--get-month-number
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
620 (substring datestring (match-beginning 2)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
621 (match-end 2))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
622 (setq year (read (substring datestring (match-beginning 3)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
623 (match-end 3)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
624 ( ;; date contains month names -- non-european-style
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
625 (and (not european-calendar-style)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
626 (string-match (concat "\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
627 "\\([A-Za-z][^ ]+\\)[ \t/]\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
628 "0?\\([123]?[0-9]\\),?[ \t/]\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
629 "\\([0-9]\\{4\\}\\)")
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
630 datestring))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
631 (setq day (read (substring datestring (match-beginning 2)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
632 (match-end 2))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
633 (setq month (icalendar--get-month-number
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
634 (substring datestring (match-beginning 1)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
635 (match-end 1))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
636 (setq year (read (substring datestring (match-beginning 3)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
637 (match-end 3)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
638 (t
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
639 nil)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
640 (if (> day 0)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
641 (let ((mdy (calendar-gregorian-from-absolute
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
642 (+ (calendar-absolute-from-gregorian (list month day
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
643 year))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
644 (or day-shift 0)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
645 (format "%04d%02d%02d" (nth 2 mdy) (nth 0 mdy) (nth 1 mdy)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
646 nil)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
647
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
648 (defun icalendar--diarytime-to-isotime (timestring ampmstring)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
649 "Convert a a time like 9:30pm to an iso-conform string like T213000.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
650 In this example the TIMESTRING would be \"9:30\" and the AMPMSTRING
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
651 would be \"pm\"."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
652 (if timestring
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
653 (let ((starttimenum (read (icalendar--rris ":" "" timestring))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
654 ;; take care of am/pm style
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
655 (if (and ampmstring (string= "pm" ampmstring))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
656 (setq starttimenum (+ starttimenum 1200)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
657 (format "T%04d00" starttimenum))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
658 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
659
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
660 (defun icalendar--convert-string-for-export (string)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
661 "Escape comma and other critical characters in STRING."
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
662 (icalendar--rris "," "\\\\," string))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
663
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
664 (defun icalendar--convert-string-for-import (string)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
665 "Remove escape chars for comma, semicolon etc. from STRING."
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
666 (icalendar--rris
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
667 "\\\\n" "\n " (icalendar--rris
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
668 "\\\\\"" "\"" (icalendar--rris
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
669 "\\\\;" ";" (icalendar--rris
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
670 "\\\\," "," string)))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
671
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
672 ;; ======================================================================
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
673 ;; Export -- convert emacs-diary to icalendar
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
674 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
675
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
676 ;;;###autoload
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
677 (defun icalendar-export-file (diary-filename ical-filename)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
678 "Export diary file to iCalendar format.
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
679 All diary entries in the file DIARY-FILENAME are converted to iCalendar
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
680 format. The result is appended to the file ICAL-FILENAME."
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
681 (interactive "FExport diary data from file:
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
682 Finto iCalendar file: ")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
683 (save-current-buffer
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
684 (set-buffer (find-file diary-filename))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
685 (icalendar-export-region (point-min) (point-max) ical-filename)))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
686
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
687 (defalias 'icalendar-convert-diary-to-ical 'icalendar-export-file)
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
688 (make-obsolete 'icalendar-convert-diary-to-ical 'icalendar-export-file)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
689
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
690 ;;;###autoload
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
691 (defun icalendar-export-region (min max ical-filename)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
692 "Export region in diary file to iCalendar format.
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
693 All diary entries in the region from MIN to MAX in the current buffer are
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
694 converted to iCalendar format. The result is appended to the file
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
695 ICAL-FILENAME.
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
696 This function attempts to return t if something goes wrong. In this
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
697 case an error string which describes all the errors and problems is
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
698 written into the buffer `*icalendar-errors*'."
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
699 (interactive "r
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
700 FExport diary data into iCalendar file: ")
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
701 (let ((result "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
702 (start 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
703 (entry-main "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
704 (entry-rest "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
705 (header "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
706 (contents)
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
707 (found-error nil)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
708 (nonmarker (concat "^" (regexp-quote diary-nonmarking-symbol)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
709 "?")))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
710 ;; prepare buffer with error messages
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
711 (save-current-buffer
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
712 (set-buffer (get-buffer-create "*icalendar-errors*"))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
713 (erase-buffer))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
714
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
715 ;; here we go
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
716 (save-excursion
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
717 (goto-char min)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
718 (while (re-search-forward
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
719 "^\\([^ \t\n].+\\)\\(\\(\n[ \t].*\\)*\\)" max t)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
720 (setq entry-main (match-string 1))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
721 (if (match-beginning 2)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
722 (setq entry-rest (match-string 2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
723 (setq entry-rest ""))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
724 (setq header (format "\nBEGIN:VEVENT\nUID:emacs%d%d%d"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
725 (car (current-time))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
726 (cadr (current-time))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
727 (car (cddr (current-time)))))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
728 (condition-case error-val
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
729 (progn
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
730 (setq contents
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
731 (or
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
732 ;; anniversaries -- %%(diary-anniversary ...)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
733 (icalendar--convert-anniversary-to-ical nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
734 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
735 ;; cyclic events -- %%(diary-cyclic ...)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
736 (icalendar--convert-cyclic-to-ical nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
737 ;; diary-date -- %%(diary-date ...)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
738 (icalendar--convert-date-to-ical nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
739 ;; float events -- %%(diary-float ...)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
740 (icalendar--convert-float-to-ical nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
741 ;; block events -- %%(diary-block ...)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
742 (icalendar--convert-block-to-ical nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
743 ;; other sexp diary entries
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
744 (icalendar--convert-sexp-to-ical nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
745 ;; weekly by day -- Monday 8:30 Team meeting
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
746 (icalendar--convert-weekly-to-ical nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
747 ;; yearly by day -- 1 May Tag der Arbeit
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
748 (icalendar--convert-yearly-to-ical nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
749 ;; "ordinary" events, start and end time given
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
750 ;; 1 Feb 2003 blah
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
751 (icalendar--convert-ordinary-to-ical nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
752 ;; everything else
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
753 ;; Oops! what's that?
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
754 (error "Could not parse entry")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
755 (unless (string= entry-rest "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
756 (setq contents
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
757 (concat contents "\nDESCRIPTION:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
758 (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
759 entry-rest))))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
760 (setq result (concat result header contents "\nEND:VEVENT")))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
761 ;; handle errors
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
762 (error
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
763 (setq found-error t)
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
764 (save-current-buffer
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
765 (set-buffer (get-buffer-create "*icalendar-errors*"))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
766 (insert (format "Error in line %d -- %s: `%s'\n"
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
767 (count-lines (point-min) (point))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
768 (cadr error-val)
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
769 entry-main))))))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
770
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
771 ;; we're done, insert everything into the file
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
772 (save-current-buffer
60235
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
773 (let ((coding-system-for-write 'utf-8))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
774 (set-buffer (find-file ical-filename))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
775 (goto-char (point-max))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
776 (insert "BEGIN:VCALENDAR")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
777 (insert "\nPRODID:-//Emacs//NONSGML icalendar.el//EN")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
778 (insert "\nVERSION:2.0")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
779 (insert result)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
780 (insert "\nEND:VCALENDAR\n")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
781 ;; save the diary file
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
782 (save-buffer))))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
783 found-error))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
784
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
785 ;; subroutines
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
786 (defun icalendar--convert-ordinary-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
787 "Convert \"ordinary\" diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
788
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
789 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
790 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
791 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
792 "\\([^ /]+[ /]+[^ /]+[ /]+[^ ]+\\)\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
793 "\\(0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
794 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
795 "-0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
796 "\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
797 "\\s-*\\(.*\\)")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
798 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
799 (let* ((datetime (substring entry-main (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
800 (match-end 1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
801 (startisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
802 datetime))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
803 (endisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
804 datetime 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
805 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
806 (if (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
807 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
808 (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
809 (match-end 3))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
810 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
811 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
812 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
813 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
814 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
815 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
816 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
817 (if (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
818 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
819 (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
820 (match-end 6))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
821 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
822 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
823 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
824 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
825 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
826 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
827 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
828 (substring entry-main (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
829 (match-end 8)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
830 (icalendar--dmsg "ordinary %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
831
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
832 (unless startisostring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
833 (error "Could not parse date"))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
834 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
835 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
836 (let ((time
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
837 (read (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
838 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
839 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
840 (+ 10000 time))))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
841 (concat "\nDTSTART;"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
842 (if starttimestring "VALUE=DATE-TIME:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
843 "VALUE=DATE:")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
844 startisostring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
845 (or starttimestring "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
846 "\nDTEND;"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
847 (if endtimestring "VALUE=DATE-TIME:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
848 "VALUE=DATE:")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
849 (if starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
850 startisostring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
851 endisostring)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
852 (or endtimestring "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
853 "\nSUMMARY:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
854 summary))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
855 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
856 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
857
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
858 (defun icalendar--convert-weekly-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
859 "Convert weekly diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
860
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
861 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
862 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
863 (if (and (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
864 "\\([a-z]+\\)\\s-+"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
865 "\\(0?\\([1-9][0-9]?:[0-9][0-9]\\)"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
866 "\\([ap]m\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
867 "\\(-0?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
868 "\\([1-9][0-9]?:[0-9][0-9]\\)"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
869 "\\([ap]m\\)?\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
870 "\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
871 "\\s-*\\(.*\\)$")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
872 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
873 (icalendar--get-weekday-abbrev
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
874 (substring entry-main (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
875 (match-end 1))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
876 (let* ((day (icalendar--get-weekday-abbrev
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
877 (substring entry-main (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
878 (match-end 1))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
879 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
880 (if (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
881 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
882 (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
883 (match-end 3))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
884 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
885 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
886 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
887 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
888 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
889 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
890 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
891 (if (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
892 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
893 (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
894 (match-end 6))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
895 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
896 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
897 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
898 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
899 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
900 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
901 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
902 (substring entry-main (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
903 (match-end 8)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
904 (icalendar--dmsg "weekly %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
905
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
906 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
907 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
908 (let ((time (read
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
909 (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
910 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
911 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
912 (+ 10000 time))))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
913 (concat "\nDTSTART;"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
914 (if starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
915 "VALUE=DATE-TIME:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
916 "VALUE=DATE:")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
917 ;; find the correct week day,
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
918 ;; 1st january 2000 was a saturday
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
919 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
920 "200001%02d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
921 (+ (icalendar--get-weekday-number day) 2))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
922 (or starttimestring "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
923 "\nDTEND;"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
924 (if endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
925 "VALUE=DATE-TIME:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
926 "VALUE=DATE:")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
927 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
928 "200001%02d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
929 ;; end is non-inclusive!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
930 (+ (icalendar--get-weekday-number day)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
931 (if endtimestring 2 3)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
932 (or endtimestring "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
933 "\nSUMMARY:" summary
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
934 "\nRRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY="
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
935 day))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
936 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
937 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
938
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
939 (defun icalendar--convert-yearly-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
940 "Convert yearly diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
941
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
942 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
943 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
944 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
945 (if european-calendar-style
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
946 "0?\\([1-9]+[0-9]?\\)\\s-+\\([a-z]+\\)\\s-+"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
947 "\\([a-z]+\\)\\s-+0?\\([1-9]+[0-9]?\\)\\s-+")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
948 "\\*?\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
949 "\\(0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
950 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
951 "-0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
952 "\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
953 "\\s-*\\([^0-9]+.*\\)$" ; must not match years
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
954 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
955 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
956 (let* ((daypos (if european-calendar-style 1 2))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
957 (monpos (if european-calendar-style 2 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
958 (day (read (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
959 (match-beginning daypos)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
960 (match-end daypos))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
961 (month (icalendar--get-month-number
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
962 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
963 (match-beginning monpos)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
964 (match-end monpos))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
965 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
966 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
967 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
968 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
969 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
970 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
971 (if (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
972 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
973 (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
974 (match-end 5))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
975 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
976 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
977 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
978 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
979 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
980 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
981 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
982 (if (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
983 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
984 (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
985 (match-end 8))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
986 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
987 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
988 (substring entry-main (match-beginning 9)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
989 (match-end 9)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
990 (icalendar--dmsg "yearly %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
991
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
992 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
993 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
994 (let ((time (read
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
995 (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
996 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
997 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
998 (+ 10000 time))))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
999 (concat "\nDTSTART;"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1000 (if starttimestring "VALUE=DATE-TIME:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1001 "VALUE=DATE:")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1002 (format "1900%02d%02d" month day)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1003 (or starttimestring "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1004 "\nDTEND;"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1005 (if endtimestring "VALUE=DATE-TIME:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1006 "VALUE=DATE:")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1007 ;; end is not included! shift by one day
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1008 (icalendar--date-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1009 (list month day 1900)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1010 (if endtimestring 0 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1011 (or endtimestring "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1012 "\nSUMMARY:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1013 summary
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1014 "\nRRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH="
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1015 (format "%2d" month)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1016 ";BYMONTHDAY="
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1017 (format "%2d" day)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1018 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1019 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1020
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1021 (defun icalendar--convert-sexp-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1022 "Convert complex sexp diary entry to icalendar format -- unsupported!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1023
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1024 FIXME!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1025
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1026 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1027 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1028 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1029 "%%(\\([^)]+\\))\\s-*\\(.*\\)")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1030 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1031 (progn
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1032 (icalendar--dmsg "diary-sexp %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1033 (error "Sexp-entries are not supported yet"))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1034 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1035 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1036
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1037 (defun icalendar--convert-block-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1038 "Convert block diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1039
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1040 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1041 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1042 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1043 "%%(diary-block \\([^ /]+[ /]+[^ /]+[ /]+[^ ]+\\)"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1044 " +\\([^ /]+[ /]+[^ /]+[ /]+[^ ]+\\))\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1045 "\\(0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1046 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1047 "-0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1048 "\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1049 "\\s-*\\(.*\\)")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1050 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1051 (let* ((startstring (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1052 (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1053 (match-end 1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1054 (endstring (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1055 (match-beginning 2)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1056 (match-end 2)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1057 (startisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1058 startstring))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1059 (endisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1060 endstring))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1061 (endisostring+1 (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1062 endstring 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1063 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1064 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1065 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1066 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1067 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1068 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1069 (if (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1070 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1071 (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1072 (match-end 5))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1073 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1074 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1075 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1076 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1077 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1078 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1079 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1080 (if (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1081 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1082 (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1083 (match-end 8))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1084 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1085 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1086 (substring entry-main (match-beginning 9)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1087 (match-end 9)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1088 (icalendar--dmsg "diary-block %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1089 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1090 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1091 (let ((time
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1092 (read (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1093 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1094 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1095 (+ 10000 time))))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1096 (if starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1097 ;; with time -> write rrule
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1098 (concat "\nDTSTART;VALUE=DATE-TIME:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1099 startisostring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1100 starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1101 "\nDTEND;VALUE=DATE-TIME:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1102 startisostring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1103 endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1104 "\nSUMMARY:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1105 summary
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1106 "\nRRULE:FREQ=DAILY;INTERVAL=1;UNTIL="
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1107 endisostring)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1108 ;; no time -> write long event
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1109 (concat "\nDTSTART;VALUE=DATE:" startisostring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1110 "\nDTEND;VALUE=DATE:" endisostring+1
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1111 "\nSUMMARY:" summary)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1112 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1113 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1114
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1115 (defun icalendar--convert-float-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1116 "Convert float diary entry to icalendar format -- unsupported!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1117
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1118 FIXME!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1119
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1120 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1121 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1122 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1123 "%%(diary-float \\([^)]+\\))\\s-*\\(.*\\)")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1124 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1125 (progn
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1126 (icalendar--dmsg "diary-float %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1127 (error "`diary-float' is not supported yet"))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1128 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1129 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1130
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1131 (defun icalendar--convert-date-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1132 "Convert `diary-date' diary entry to icalendar format -- unsupported!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1133
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1134 FIXME!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1135
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1136 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1137 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1138 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1139 "%%(diary-date \\([^)]+\\))\\s-*\\(.*\\)")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1140 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1141 (progn
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1142 (icalendar--dmsg "diary-date %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1143 (error "`diary-date' is not supported yet"))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1144 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1145 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1146
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1147 (defun icalendar--convert-cyclic-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1148 "Convert `diary-cyclic' diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1149
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1150 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1151 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1152 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1153 "%%(diary-cyclic \\([^ ]+\\) +"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1154 "\\([^ /]+[ /]+[^ /]+[ /]+[^ ]+\\))\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1155 "\\(0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1156 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1157 "-0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1158 "\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1159 "\\s-*\\(.*\\)")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1160 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1161 (let* ((frequency (substring entry-main (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1162 (match-end 1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1163 (datetime (substring entry-main (match-beginning 2)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1164 (match-end 2)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1165 (startisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1166 datetime))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1167 (endisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1168 datetime))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1169 (endisostring+1 (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1170 datetime 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1171 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1172 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1173 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1174 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1175 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1176 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1177 (if (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1178 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1179 (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1180 (match-end 5))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1181 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1182 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1183 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1184 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1185 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1186 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1187 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1188 (if (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1189 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1190 (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1191 (match-end 8))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1192 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1193 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1194 (substring entry-main (match-beginning 9)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1195 (match-end 9)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1196 (icalendar--dmsg "diary-cyclic %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1197 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1198 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1199 (let ((time
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1200 (read (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1201 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1202 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1203 (+ 10000 time))))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1204 (concat "\nDTSTART;"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1205 (if starttimestring "VALUE=DATE-TIME:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1206 "VALUE=DATE:")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1207 startisostring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1208 (or starttimestring "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1209 "\nDTEND;"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1210 (if endtimestring "VALUE=DATE-TIME:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1211 "VALUE=DATE:")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1212 (if endtimestring endisostring endisostring+1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1213 (or endtimestring "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1214 "\nSUMMARY:" summary
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1215 "\nRRULE:FREQ=DAILY;INTERVAL=" frequency
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1216 ;; strange: korganizer does not expect
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1217 ;; BYSOMETHING here...
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1218 ))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1219 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1220 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1221
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1222 (defun icalendar--convert-anniversary-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1223 "Convert `diary-anniversary' diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1224
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1225 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1226 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1227 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1228 "%%(diary-anniversary \\([^)]+\\))\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1229 "\\(0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1230 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1231 "-0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1232 "\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1233 "\\s-*\\(.*\\)")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1234 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1235 (let* ((datetime (substring entry-main (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1236 (match-end 1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1237 (startisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1238 datetime))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1239 (endisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1240 datetime 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1241 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1242 (if (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1243 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1244 (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1245 (match-end 3))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1246 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1247 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1248 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1249 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1250 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1251 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1252 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1253 (if (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1254 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1255 (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1256 (match-end 6))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1257 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1258 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1259 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1260 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1261 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1262 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1263 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1264 (substring entry-main (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1265 (match-end 8)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1266 (icalendar--dmsg "diary-anniversary %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1267 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1268 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1269 (let ((time
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1270 (read (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1271 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1272 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1273 (+ 10000 time))))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1274 (concat "\nDTSTART;"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1275 (if starttimestring "VALUE=DATE-TIME:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1276 "VALUE=DATE:")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1277 startisostring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1278 (or starttimestring "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1279 "\nDTEND;"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1280 (if endtimestring "VALUE=DATE-TIME:"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1281 "VALUE=DATE:")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1282 endisostring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1283 (or endtimestring "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1284 "\nSUMMARY:" summary
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1285 "\nRRULE:FREQ=YEARLY;INTERVAL=1"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1286 ;; the following is redundant,
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1287 ;; but korganizer seems to expect this... ;(
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1288 ;; and evolution doesn't understand it... :(
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1289 ;; so... who is wrong?!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1290 ";BYMONTH="
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1291 (substring startisostring 4 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1292 ";BYMONTHDAY="
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1293 (substring startisostring 6 8)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1294 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1295 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1296
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1297 ;; ======================================================================
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1298 ;; Import -- convert icalendar to emacs-diary
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1299 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1300
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
1301 ;;;###autoload
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1302 (defun icalendar-import-file (ical-filename diary-filename
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1303 &optional non-marking)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1304 "Import a iCalendar file and append to a diary file.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1305 Argument ICAL-FILENAME output iCalendar file.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1306 Argument DIARY-FILENAME input `diary-file'.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1307 Optional argument NON-MARKING determines whether events are created as
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1308 non-marking or not."
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
1309 (interactive "fImport iCalendar data from file:
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1310 Finto diary file:
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1311 p")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1312 ;; clean up the diary file
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1313 (save-current-buffer
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1314 ;; now load and convert from the ical file
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1315 (set-buffer (find-file ical-filename))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1316 (icalendar-import-buffer diary-filename t non-marking)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1317
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
1318 ;;;###autoload
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1319 (defun icalendar-import-buffer (&optional diary-file do-not-ask
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1320 non-marking)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1321 "Extract iCalendar events from current buffer.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1322
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1323 This function searches the current buffer for the first iCalendar
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1324 object, reads it and adds all VEVENT elements to the diary
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1325 DIARY-FILE.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1326
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1327 It will ask for each appointment whether to add it to the diary
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1328 when DO-NOT-ASK is non-nil. When called interactively,
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1329 DO-NOT-ASK is set to t, so that you are asked fore each event.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1330
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1331 NON-MARKING determines whether diary events are created as
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1332 non-marking.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1333
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1334 Return code t means that importing worked well, return code nil
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1335 means that an error has occured. Error messages will be in the
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1336 buffer `*icalendar-errors*'."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1337 (interactive)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1338 (save-current-buffer
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1339 ;; prepare ical
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1340 (message "Preparing icalendar...")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1341 (set-buffer (icalendar--get-unfolded-buffer (current-buffer)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1342 (goto-char (point-min))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1343 (message "Preparing icalendar...done")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1344 (if (re-search-forward "^BEGIN:VCALENDAR\\s-*$" nil t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1345 (let (ical-contents ical-errors)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1346 ;; read ical
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1347 (message "Reading icalendar...")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1348 (beginning-of-line)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1349 (setq ical-contents (icalendar--read-element nil nil))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1350 (message "Reading icalendar...done")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1351 ;; convert ical
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1352 (message "Converting icalendar...")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1353 (setq ical-errors (icalendar--convert-ical-to-diary
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1354 ical-contents
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1355 diary-file do-not-ask non-marking))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1356 (when diary-file
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1357 ;; save the diary file if it is visited already
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1358 (let ((b (find-buffer-visiting diary-file)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1359 (when b
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1360 (save-current-buffer
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1361 (set-buffer b)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1362 (save-buffer)))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1363 (message "Converting icalendar...done")
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1364 ;; return t if no error occured
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1365 (not ical-errors))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1366 (message
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1367 "Current buffer does not contain icalendar contents!")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1368 ;; return nil, i.e. import did not work
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1369 nil)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1370
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1371 (defalias 'icalendar-extract-ical-from-buffer 'icalendar-import-buffer)
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
1372 (make-obsolete 'icalendar-extract-ical-from-buffer 'icalendar-import-buffer)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1373
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1374 (defun icalendar--format-ical-event (event)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1375 "Create a string representation of an iCalendar EVENT."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1376 (let ((string icalendar-import-format)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1377 (conversion-list
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1378 '(("%d" DESCRIPTION icalendar-import-format-description)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1379 ("%s" SUMMARY icalendar-import-format-subject)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1380 ("%l" LOCATION icalendar-import-format-location)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1381 ("%o" ORGANIZER icalendar-import-format-organizer))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1382 ;; convert the specifiers in the format string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1383 (mapcar (lambda (i)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1384 (let* ((spec (car i))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1385 (prop (cadr i))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1386 (format (car (cddr i)))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1387 (contents (icalendar--get-event-property event prop))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1388 (formatted-contents ""))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1389 (when (and contents (> (length contents) 0))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1390 (setq formatted-contents
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1391 (icalendar--rris "%s"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1392 (icalendar--convert-string-for-import
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1393 contents)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1394 (symbol-value format))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1395 (setq string (icalendar--rris spec
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1396 formatted-contents
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1397 string))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1398 conversion-list)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1399 string))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1400
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1401 (defun icalendar--convert-ical-to-diary (ical-list diary-file
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1402 &optional do-not-ask
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1403 non-marking)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1404 "Convert an iCalendar file to an Emacs diary file.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1405 Import VEVENTS from the iCalendar object ICAL-LIST and saves them to a
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1406 DIARY-FILE. If DO-NOT-ASK is nil the user is asked for each event
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1407 whether to actually import it. NON-MARKING determines whether diary
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1408 events are created as non-marking.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1409 This function attempts to return t if something goes wrong. In this
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1410 case an error string which describes all the errors and problems is
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1411 written into the buffer `*icalendar-errors*'."
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1412 (let* ((ev (icalendar--all-events ical-list))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1413 (error-string "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1414 (event-ok t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1415 (found-error nil)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1416 e diary-string)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1417 ;; step through all events/appointments
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1418 (while ev
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1419 (setq e (car ev))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1420 (setq ev (cdr ev))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1421 (setq event-ok nil)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1422 (condition-case error-val
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1423 (let* ((dtstart (icalendar--get-event-property e 'DTSTART))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1424 (dtstart-dec (icalendar--decode-isodatetime dtstart))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1425 (start-d (icalendar--datetime-to-diary-date
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1426 dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1427 (start-t (icalendar--datetime-to-colontime dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1428 (dtend (icalendar--get-event-property e 'DTEND))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1429 (dtend-dec (icalendar--decode-isodatetime dtend))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1430 (dtend-1-dec (icalendar--decode-isodatetime dtend -1))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1431 end-d
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1432 end-1-d
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1433 end-t
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1434 (subject (icalendar--convert-string-for-import
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1435 (or (icalendar--get-event-property e 'SUMMARY)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1436 "No Subject")))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1437 (rrule (icalendar--get-event-property e 'RRULE))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1438 (rdate (icalendar--get-event-property e 'RDATE))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1439 (duration (icalendar--get-event-property e 'DURATION)))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1440 (icalendar--dmsg "%s: `%s'" start-d subject)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1441 ;; check whether start-time is missing
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1442 (if (and dtstart
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1443 (string=
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1444 (cadr (icalendar--get-event-property-attributes
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1445 e 'DTSTART))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1446 "DATE"))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1447 (setq start-t nil))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1448 (when duration
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1449 (let ((dtend-dec-d (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1450 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1451 (icalendar--decode-isoduration duration)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1452 (dtend-1-dec-d (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1453 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1454 (icalendar--decode-isoduration duration
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1455 t))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1456 (if (and dtend-dec (not (eq dtend-dec dtend-dec-d)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1457 (message "Inconsistent endtime and duration for %s"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1458 subject))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1459 (setq dtend-dec dtend-dec-d)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1460 (setq dtend-1-dec dtend-1-dec-d)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1461 (setq end-d (if dtend-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1462 (icalendar--datetime-to-diary-date dtend-dec)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1463 start-d))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1464 (setq end-1-d (if dtend-1-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1465 (icalendar--datetime-to-diary-date dtend-1-dec)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1466 start-d))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1467 (setq end-t (if (and
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1468 dtend-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1469 (not (string=
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1470 (cadr
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1471 (icalendar--get-event-property-attributes
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1472 e 'DTEND))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1473 "DATE")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1474 (icalendar--datetime-to-colontime dtend-dec)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1475 start-t))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1476 (icalendar--dmsg "start-d: %s, end-d: %s" start-d end-d)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1477 (cond
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1478 ;; recurring event
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1479 (rrule
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1480 (setq diary-string
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1481 (icalendar--convert-recurring-to-diary e dtstart-dec start-t
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1482 end-t))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1483 (setq event-ok t))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1484 (rdate
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1485 (icalendar--dmsg "rdate event")
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1486 (setq diary-string "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1487 (mapcar (lambda (datestring)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1488 (setq diary-string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1489 (concat diary-string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1490 (format "......"))))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1491 (icalendar--split-value rdate)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1492 ;; non-recurring event
60235
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
1493 ;; all-day event
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1494 ((not (string= start-d end-d))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1495 (setq diary-string
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1496 (icalendar--convert-non-recurring-all-day-to-diary
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1497 e start-d end-1-d))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1498 (setq event-ok t))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1499 ;; not all-day
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1500 ((and start-t (or (not end-t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1501 (not (string= start-t end-t))))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1502 (setq diary-string
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1503 (icalendar--convert-non-recurring-not-all-day-to-diary
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1504 e dtstart-dec dtend-dec start-t end-t))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1505 (setq event-ok t))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1506 ;; all-day event
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1507 (t
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1508 (icalendar--dmsg "all day event")
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1509 (setq diary-string (icalendar--datetime-to-diary-date
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1510 dtstart-dec "/"))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1511 (setq event-ok t)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1512 ;; add all other elements unless the user doesn't want to have
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1513 ;; them
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1514 (if event-ok
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1515 (progn
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1516 (setq diary-string
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1517 (concat diary-string " "
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1518 (icalendar--format-ical-event e)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1519 (if do-not-ask (setq subject nil))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1520 (icalendar--add-diary-entry diary-string diary-file
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1521 non-marking subject))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1522 ;; event was not ok
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1523 (setq found-error t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1524 (setq error-string
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1525 (format "%s\nCannot handle this event:%s"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1526 error-string e))))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1527 ;; FIXME: inform user about ignored event properties
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1528 ;; handle errors
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1529 (error
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1530 (message "Ignoring event \"%s\"" e)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1531 (setq found-error t)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1532 (setq error-string (format "%s\n%s\nCannot handle this event: %s"
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1533 error-val error-string e))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1534 (message error-string))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1535 (if found-error
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1536 (save-current-buffer
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1537 (set-buffer (get-buffer-create "*icalendar-errors*"))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1538 (erase-buffer)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1539 (insert error-string)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1540 (message "Converting icalendar...done")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1541 found-error))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1542
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1543 ;; subroutines for importing
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1544 (defun icalendar--convert-recurring-to-diary (e dtstart-dec start-t end-t)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1545 "Convert recurring icalendar event E to diary format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1546
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1547 DTSTART-DEC is the DTSTART property of E.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1548 START-T is the event's start time in diary format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1549 END-T is the event's end time in diary format."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1550 (icalendar--dmsg "recurring event")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1551 (let* ((rrule (icalendar--get-event-property e 'RRULE))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1552 (rrule-props (icalendar--split-value rrule))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1553 (frequency (cadr (assoc 'FREQ rrule-props)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1554 (until (cadr (assoc 'UNTIL rrule-props)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1555 (count (cadr (assoc 'COUNT rrule-props)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1556 (interval (read (or (cadr (assoc 'INTERVAL rrule-props)) "1")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1557 (dtstart-conv (icalendar--datetime-to-diary-date dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1558 (until-conv (icalendar--datetime-to-diary-date
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1559 (icalendar--decode-isodatetime until)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1560 (until-1-conv (icalendar--datetime-to-diary-date
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1561 (icalendar--decode-isodatetime until -1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1562 (result ""))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1563
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1564 ;; FIXME FIXME interval!!!!!!!!!!!!!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1565
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1566 (when count
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1567 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1568 (message "Must not have UNTIL and COUNT -- ignoring COUNT element!")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1569 (let ((until-1 0))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1570 (cond ((string-equal frequency "DAILY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1571 (setq until (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1572 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1573 (list 0 0 0 (* (read count) interval) 0 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1574 (setq until-1 (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1575 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1576 (list 0 0 0 (* (- (read count) 1) interval)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1577 0 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1578 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1579 ((string-equal frequency "WEEKLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1580 (setq until (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1581 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1582 (list 0 0 0 (* (read count) 7 interval) 0 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1583 (setq until-1 (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1584 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1585 (list 0 0 0 (* (- (read count) 1) 7
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1586 interval) 0 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1587 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1588 ((string-equal frequency "MONTHLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1589 (setq until (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1590 dtstart-dec (list 0 0 0 0 (* (- (read count) 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1591 interval) 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1592 (setq until-1 (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1593 dtstart-dec (list 0 0 0 0 (* (- (read count) 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1594 interval) 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1595 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1596 ((string-equal frequency "YEARLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1597 (setq until (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1598 dtstart-dec (list 0 0 0 0 0 (* (- (read count) 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1599 interval))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1600 (setq until-1 (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1601 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1602 (list 0 0 0 0 0 (* (- (read count) 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1603 interval))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1604 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1605 (t
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1606 (message "Cannot handle COUNT attribute for `%s' events."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1607 frequency)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1608 (setq until-conv (icalendar--datetime-to-diary-date until))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1609 (setq until-1-conv (icalendar--datetime-to-diary-date until-1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1610 ))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1611 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1612 (cond ((string-equal frequency "WEEKLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1613 (if (not start-t)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1614 (progn
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1615 ;; weekly and all-day
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1616 (icalendar--dmsg "weekly all-day")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1617 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1618 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1619 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1620 (concat "%%%%(and "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1621 "(diary-cyclic %d %s) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1622 "(diary-block %s %s))")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1623 (* interval 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1624 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1625 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1626 (if count until-1-conv until-conv)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1627 ))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1628 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1629 (format "%%%%(and (diary-cyclic %d %s))"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1630 (* interval 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1631 dtstart-conv))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1632 ;; weekly and not all-day
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1633 (let* ((byday (cadr (assoc 'BYDAY rrule-props)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1634 (weekday
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1635 (icalendar--get-weekday-number byday)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1636 (icalendar--dmsg "weekly not-all-day")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1637 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1638 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1639 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1640 (concat "%%%%(and "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1641 "(diary-cyclic %d %s) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1642 "(diary-block %s %s)) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1643 "%s%s%s")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1644 (* interval 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1645 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1646 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1647 until-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1648 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1649 (if end-t "-" "") (or end-t "")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1650 ;; no limit
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1651 ;; FIXME!!!!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1652 ;; DTSTART;VALUE=DATE-TIME:20030919T090000
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1653 ;; DTEND;VALUE=DATE-TIME:20030919T113000
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1654 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1655 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1656 "%%%%(and (diary-cyclic %s %s)) %s%s%s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1657 (* interval 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1658 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1659 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1660 (if end-t "-" "") (or end-t "")))))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1661 ;; yearly
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1662 ((string-equal frequency "YEARLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1663 (icalendar--dmsg "yearly")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1664 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1665 (setq result (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1666 (concat "%%%%(and (diary-date %s %s t) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1667 "(diary-block %s %s)) %s%s%s")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1668 (if european-calendar-style (nth 3 dtstart-dec)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1669 (nth 4 dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1670 (if european-calendar-style (nth 4 dtstart-dec)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1671 (nth 3 dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1672 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1673 until-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1674 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1675 (if end-t "-" "") (or end-t "")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1676 (setq result (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1677 "%%%%(and (diary-anniversary %s)) %s%s%s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1678 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1679 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1680 (if end-t "-" "") (or end-t "")))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1681 ;; monthly
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1682 ((string-equal frequency "MONTHLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1683 (icalendar--dmsg "monthly")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1684 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1685 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1686 "%%%%(and (diary-date %s %s %s) (diary-block %s %s)) %s%s%s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1687 (if european-calendar-style (nth 3 dtstart-dec) "t")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1688 (if european-calendar-style "t" (nth 3 dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1689 "t"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1690 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1691 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1692 until-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1693 "1 1 9999") ;; FIXME: should be unlimited
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1694 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1695 (if end-t "-" "") (or end-t ""))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1696 ;; daily
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1697 ((and (string-equal frequency "DAILY"))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1698 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1699 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1700 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1701 (concat "%%%%(and (diary-cyclic %s %s) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1702 "(diary-block %s %s)) %s%s%s")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1703 interval dtstart-conv dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1704 (if count until-1-conv until-conv)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1705 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1706 (if end-t "-" "") (or end-t "")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1707 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1708 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1709 "%%%%(and (diary-cyclic %s %s)) %s%s%s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1710 interval
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1711 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1712 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1713 (if end-t "-" "") (or end-t ""))))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1714 ;; Handle exceptions from recurrence rules
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1715 (let ((ex-dates (icalendar--get-event-properties e 'EXDATE)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1716 (while ex-dates
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1717 (let* ((ex-start (icalendar--decode-isodatetime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1718 (car ex-dates)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1719 (ex-d (icalendar--datetime-to-diary-date
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1720 ex-start)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1721 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1722 (icalendar--rris "^%%(\\(and \\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1723 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1724 "%%%%(and (not (diary-date %s)) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1725 ex-d)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1726 result)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1727 (setq ex-dates (cdr ex-dates))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1728 ;; FIXME: exception rules are not recognized
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1729 (if (icalendar--get-event-property e 'EXRULE)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1730 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1731 (concat result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1732 "\n Exception rules: "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1733 (icalendar--get-event-properties
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1734 e 'EXRULE))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1735 result))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1736
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1737 (defun icalendar--convert-non-recurring-all-day-to-diary (event start-d end-d)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1738 "Convert non-recurring icalendar EVENT to diary format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1739
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1740 DTSTART is the decoded DTSTART property of E.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1741 Argument START-D gives the first day.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1742 Argument END-D gives the last day."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1743 (icalendar--dmsg "non-recurring all-day event")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1744 (format "%%%%(and (diary-block %s %s))" start-d end-d))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1745
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1746 (defun icalendar--convert-non-recurring-not-all-day-to-diary (event dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1747 dtend-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1748 start-t
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1749 end-t)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1750 "Convert recurring icalendar EVENT to diary format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1751
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1752 DTSTART-DEC is the decoded DTSTART property of E.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1753 DTEND-DEC is the decoded DTEND property of E.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1754 START-T is the event's start time in diary format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1755 END-T is the event's end time in diary format."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1756 (icalendar--dmsg "not all day event")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1757 (cond (end-t
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1758 (format "%s %s-%s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1759 (icalendar--datetime-to-diary-date
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1760 dtstart-dec "/")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1761 start-t end-t))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1762 (t
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1763 (format "%s %s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1764 (icalendar--datetime-to-diary-date
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1765 dtstart-dec "/")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1766 start-t))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1767
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1768 (defun icalendar--add-diary-entry (string diary-file non-marking
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1769 &optional subject)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1770 "Add STRING to the diary file DIARY-FILE.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1771 STRING must be a properly formatted valid diary entry. NON-MARKING
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1772 determines whether diary events are created as non-marking. If
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1773 SUBJECT is not nil it must be a string that gives the subject of the
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1774 entry. In this case the user will be asked whether he wants to insert
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1775 the entry."
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1776 (when (or (not subject)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1777 (y-or-n-p (format "Add appointment for `%s' to diary? "
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1778 subject)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1779 (when subject
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1780 (setq non-marking
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1781 (y-or-n-p (format "Make appointment non-marking? "))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1782 (save-window-excursion
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1783 (unless diary-file
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1784 (setq diary-file
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1785 (read-file-name "Add appointment to this diary file: ")))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1786 (make-diary-entry string non-marking diary-file))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1787
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1788 (provide 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1789
57345
f024640dc5e4 Changes from arch/CVS synchronization
Miles Bader <miles@gnu.org>
parents: 57337
diff changeset
1790 ;; arch-tag: 74fdbe8e-0451-4e38-bb61-4416e822f4fc
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1791 ;;; icalendar.el ends here