annotate lisp/calendar/icalendar.el @ 71823:6b4b6ba02f17

(CHECK_FRAME, CHECK_LIVE_FRAME): Use CHECK_TYPE.
author Kim F. Storm <storm@cua.dk>
date Wed, 12 Jul 2006 13:14:00 +0000
parents 09f294c6700a
children 9963f42a0a19
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
68721
8daf7d9a0771 Add 2006 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 66374
diff changeset
3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006 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
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62902
diff changeset
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62902
diff changeset
25 ;; Boston, MA 02110-1301, USA.
57337
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
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
100 (defconst icalendar-version "0.13"
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:
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
116 %c Class, see `icalendar-import-format-class'
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
117 %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
118 %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
119 %o Organizer, see `icalendar-import-format-organizer'
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
120 %s Summary, see `icalendar-import-format-summary'
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
121 %t Status, see `icalendar-import-format-status'
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
122 %u URL, see `icalendar-import-format-url'"
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
123 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
124 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
125
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
126 (defcustom icalendar-import-format-summary
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
127 "%s"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
128 "Format string defining how the summary element is formatted.
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
129 This applies only if the summary is not empty! `%s' is replaced
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
130 by the summary."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
131 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
132 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
133
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
134 (defcustom icalendar-import-format-description
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
135 "\n Desc: %s"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
136 "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
137 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
138 replaced by the description."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
139 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
140 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
141
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
142 (defcustom icalendar-import-format-location
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
143 "\n Location: %s"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
144 "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
145 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
146 by the location."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
147 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
148 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
149
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
150 (defcustom icalendar-import-format-organizer
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
151 "\n Organizer: %s"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
152 "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
153 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
154 replaced by the organizer."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
155 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
156 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
157
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
158 (defcustom icalendar-import-format-url
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
159 "\n URL: %s"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
160 "Format string defining how the URL element is formatted.
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
161 This applies only if the URL is not empty! `%s' is replaced by
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
162 the URL."
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
163 :type 'string
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
164 :group 'icalendar)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
165
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
166 (defcustom icalendar-import-format-status
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
167 "\n Status: %s"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
168 "Format string defining how the status element is formatted.
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
169 This applies only if the status is not empty! `%s' is replaced by
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
170 the status."
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
171 :type 'string
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
172 :group 'icalendar)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
173
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
174 (defcustom icalendar-import-format-class
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
175 "\n Class: %s"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
176 "Format string defining how the class element is formatted.
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
177 This applies only if the class is not empty! `%s' is replaced by
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
178 the class."
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
179 :type 'string
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
180 :group 'icalendar)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
181
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
182 (defvar icalendar-debug nil
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
183 "Enable icalendar debug messages.")
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
184
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
185 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
186 ;; 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
187 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
188
57652
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
189 (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
190
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
191 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
192 ;; all the other libs we need
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
193 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
194 (require 'calendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
195
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 ;; misc
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
198 ;; ======================================================================
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
199 (defun icalendar--dmsg (&rest args)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
200 "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
201 (if icalendar-debug
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
202 (apply 'message args)))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
203
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
204 ;; ======================================================================
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
205 ;; Core functionality
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
206 ;; 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
207 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
208
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
209 (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
210 "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
211 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
212 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
213 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
214 buffer."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
215 (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
216 (save-current-buffer
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
217 (set-buffer unfolded-buffer)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
218 (erase-buffer)
64432
cd3c7f95237e (icalendar--get-unfolded-buffer): Use `insert-buffer-substring' and `goto-char',
Juanma Barranquero <lekktu@gmail.com>
parents: 64085
diff changeset
219 (insert-buffer-substring folded-ical-buffer)
cd3c7f95237e (icalendar--get-unfolded-buffer): Use `insert-buffer-substring' and `goto-char',
Juanma Barranquero <lekktu@gmail.com>
parents: 64085
diff changeset
220 (goto-char (point-min))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
221 (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
222 (replace-match "" nil nil)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
223 unfolded-buffer))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
224
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
225 (defsubst icalendar--rris (&rest args)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
226 "Replace regular expression in string.
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
227 Pass ARGS to `replace-regexp-in-string' (Emacs) or to
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
228 `replace-in-string' (XEmacs)."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
229 ;; XEmacs:
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
230 (if (fboundp 'replace-in-string)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
231 (save-match-data ;; apparently XEmacs needs save-match-data
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
232 (apply 'replace-in-string args))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
233 ;; Emacs:
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
234 (apply 'replace-regexp-in-string args)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
235
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
236 (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
237 "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
238 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
239 INPARAMS gives the current parameters.....
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
240 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
241 it finds"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
242 (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
243 value
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
244 (continue t))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
245 (setq children '())
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
246 (while (and continue
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
247 (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
248 (setq name (intern (match-string 1)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
249 (backward-char 1)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
250 (setq params '())
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
251 (setq line '())
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
252 (while (looking-at ";")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
253 (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
254 (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
255 (re-search-forward "\\(\\([^;,:\"]+\\)\\|\"\\([^\"]+\\)\"\\)[;:]"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
256 nil t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
257 (backward-char 1)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
258 (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
259 (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
260 (while (looking-at ",")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
261 (re-search-forward "\\(\\([^;,:]+\\)\\|\"\\([^\"]+\\)\"\\)"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
262 nil t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
263 (if (match-string 2)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
264 (setq param-value (match-string 2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
265 (setq param-value (match-string 3)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
266 (setq param (append param param-value)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
267 (setq params (append params param)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
268 (unless (looking-at ":")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
269 (error "Oops"))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
270 (forward-char 1)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
271 (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
272 (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
273 (setq line (list name params value))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
274 (cond ((eq name 'BEGIN)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
275 (setq children
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
276 (append children
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
277 (list (icalendar--read-element (intern value)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
278 params)))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
279 ((eq name 'END)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
280 (setq continue nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
281 (t
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
282 (setq element (append element (list line))))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
283 (if invalue
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
284 (list invalue inparams element children)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
285 children)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
286
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
287 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
288 ;; helper functions for examining events
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
289 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
290
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
291 ;;(defsubst icalendar--get-all-event-properties (event)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
292 ;; "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
293 ;; (car (cddr event)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
294
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
295 (defun icalendar--get-event-property (event prop)
68930
16194e6e2a7b (icalendar--get-event-property, icalendar--get-event-property-attributes):
Juanma Barranquero <lekktu@gmail.com>
parents: 68721
diff changeset
296 "For the given EVENT return the value of the first occurrence of PROP."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
297 (catch 'found
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
298 (let ((props (car (cddr event))) pp)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
299 (while props
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
300 (setq pp (car props))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
301 (if (eq (car pp) prop)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
302 (throw 'found (car (cddr pp))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
303 (setq props (cdr props))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
304 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
305
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
306 (defun icalendar--get-event-property-attributes (event prop)
68930
16194e6e2a7b (icalendar--get-event-property, icalendar--get-event-property-attributes):
Juanma Barranquero <lekktu@gmail.com>
parents: 68721
diff changeset
307 "For the given EVENT return attributes of the first occurrence of PROP."
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
308 (catch 'found
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
309 (let ((props (car (cddr event))) pp)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
310 (while props
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
311 (setq pp (car props))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
312 (if (eq (car pp) prop)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
313 (throw 'found (cadr pp)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
314 (setq props (cdr props))))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
315 nil))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
316
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
317 (defun icalendar--get-event-properties (event prop)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
318 "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
319 (let ((props (car (cddr event))) pp result)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
320 (while props
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
321 (setq pp (car props))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
322 (if (eq (car pp) prop)
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
323 (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
324 (setq props (cdr props)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
325 result))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
326
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
327 ;; (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
328 ;; "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
329 ;; (catch 'found
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
330 ;; (let ((props (car (cddr event))) pp)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
331 ;; (while props
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
332 ;; (setq pp (car props))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
333 ;; (when (eq (car pp) prop)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
334 ;; (setcdr (cdr pp) new-value)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
335 ;; (throw 'found (car (cddr pp))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
336 ;; (setq props (cdr props)))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
337 ;; (setq props (car (cddr event)))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
338 ;; (setcar (cddr event)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
339 ;; (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
340
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
341 (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
342 "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
343 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
344 children."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
345 (let ((result nil)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
346 (children (cadr (cddr node))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
347 (when (eq (car node) name)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
348 (setq result node))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
349 ;;(message "%s" node)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
350 (when children
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
351 (let ((subresult
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
352 (delq nil
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
353 (mapcar (lambda (n)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
354 (icalendar--get-children n name))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
355 children))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
356 (if subresult
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
357 (if result
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
358 (setq result (append result subresult))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
359 (setq result subresult)))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
360 result))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
361
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
362 ; private
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
363 (defun icalendar--all-events (icalendar)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
364 "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
365 (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
366
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
367 (defun icalendar--split-value (value-string)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
368 "Split VALUE-STRING at ';='."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
369 (let ((result '())
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
370 param-name param-value)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
371 (when value-string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
372 (save-current-buffer
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
373 (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
374 (set-buffer-modified-p nil)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
375 (erase-buffer)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
376 (insert value-string)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
377 (goto-char (point-min))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
378 (while
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
379 (re-search-forward
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
380 "\\([A-Za-z0-9-]+\\)=\\(\\([^;,:]+\\)\\|\"\\([^\"]+\\)\"\\);?"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
381 nil t)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
382 (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
383 (setq param-value (match-string 2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
384 (setq result
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
385 (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
386 result))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
387
60235
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
388 (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
389 "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
390 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
391 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
392 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
393 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
394 days.
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
395
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
396 FIXME: TZID-attributes are ignored....!
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
397 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
398 (icalendar--dmsg isodatetimestring)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
399 (if isodatetimestring
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
400 ;; day/month/year must be present
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
401 (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
402 (month (read (substring isodatetimestring 4 6)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
403 (day (read (substring isodatetimestring 6 8)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
404 (hour 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
405 (minute 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
406 (second 0))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
407 (when (> (length isodatetimestring) 12)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
408 ;; hour/minute present
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
409 (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
410 (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
411 (when (> (length isodatetimestring) 14)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
412 ;; seconds present
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
413 (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
414 (when (and (> (length isodatetimestring) 15)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
415 ;; UTC specifier present
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
416 (char-equal ?Z (aref isodatetimestring 15)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
417 ;; 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
418 (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
419 ;; shift if necessary
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
420 (if day-shift
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
421 (let ((mdy (calendar-gregorian-from-absolute
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
422 (+ (calendar-absolute-from-gregorian
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
423 (list month day year))
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
424 day-shift))))
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
425 (setq month (nth 0 mdy))
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
426 (setq day (nth 1 mdy))
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
427 (setq year (nth 2 mdy))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
428 ;; create the decoded date-time
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
429 ;; FIXME!?!
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
430 (condition-case nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
431 (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
432 (error
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
433 (message "Cannot decode \"%s\"" isodatetimestring)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
434 ;; hope for the best...
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
435 (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
436 ;; isodatetimestring == nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
437 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
438
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
439 (defun icalendar--decode-isoduration (isodurationstring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
440 &optional duration-correction)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
441 "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
442 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
443 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
444 the local time zone!
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
445
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
446 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
447
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
448 FIXME: TZID-attributes are ignored....!
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
449 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
450 (if isodurationstring
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
451 (save-match-data
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
452 (string-match
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
453 (concat
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
454 "^P[+-]?\\("
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
455 "\\(\\([0-9]+\\)D\\)" ; days only
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
456 "\\|"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
457 "\\(\\(\\([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
458 "\\(\\([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
459 "\\|"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
460 "\\(\\([0-9]+\\)W\\)" ; weeks only
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
461 "\\)$") isodurationstring)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
462 (let ((seconds 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
463 (minutes 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
464 (hours 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
465 (days 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
466 (months 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
467 (years 0))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
468 (cond
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
469 ((match-beginning 2) ;days only
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
470 (setq days (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
471 (match-beginning 3)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
472 (match-end 3))))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
473 (when duration-correction
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
474 (setq days (1- days))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
475 ((match-beginning 4) ;days and time
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
476 (if (match-beginning 5)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
477 (setq days (* 7 (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
478 (match-beginning 6)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
479 (match-end 6))))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
480 (if (match-beginning 7)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
481 (setq hours (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
482 (match-beginning 8)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
483 (match-end 8)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
484 (if (match-beginning 9)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
485 (setq minutes (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
486 (match-beginning 10)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
487 (match-end 10)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
488 (if (match-beginning 11)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
489 (setq seconds (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
490 (match-beginning 12)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
491 (match-end 12))))))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
492 ((match-beginning 13) ;weeks only
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
493 (setq days (* 7 (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
494 (match-beginning 14)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
495 (match-end 14)))))))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
496 (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
497 ;; isodatetimestring == nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
498 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
499
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
500 (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
501 "Add TIME1 to TIME2.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
502 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
503 valid (year > 1900 or something)."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
504 ;; FIXME: does this function exist already?
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
505 (decode-time (encode-time
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
506 (+ (nth 0 time1) (nth 0 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
507 (+ (nth 1 time1) (nth 1 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
508 (+ (nth 2 time1) (nth 2 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
509 (+ (nth 3 time1) (nth 3 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
510 (+ (nth 4 time1) (nth 4 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
511 (+ (nth 5 time1) (nth 5 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
512 nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
513 nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
514 ;;(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
515 )))
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-noneuropean-date (datetime &optional separator)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
518 "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
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 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
522 (if datetime
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
523 (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
524 (or separator " ")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
525 (nth 3 datetime) ;day
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
526 (or separator " ")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
527 (nth 5 datetime)) ;year
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
528 ;; datetime == nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
529 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
530
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
531 (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
532 "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
533 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
534 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
535 European format: (day month year).
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
536 FIXME"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
537 (if datetime
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
538 (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
539 (or separator " ")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
540 (nth 4 datetime) ;month
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
541 (or separator " ")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
542 (nth 5 datetime)) ;year
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
543 ;; datetime == nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
544 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
545
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
546 (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
547 "Convert the decoded DATETIME to diary format.
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
548 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
549 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
550 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
551 value of `european-calendar-style'."
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
552 (if european-calendar-style
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
553 (icalendar--datetime-to-european-date datetime separator)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
554 (icalendar--datetime-to-noneuropean-date datetime separator)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
555
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
556 (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
557 "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
558 Note that this silently ignores seconds."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
559 (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
560
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
561 (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
562 "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
563 (catch 'found
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
564 (let ((num 1)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
565 (m (downcase monthname)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
566 (mapc (lambda (month)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
567 (let ((mm (downcase month)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
568 (if (or (string-equal mm m)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
569 (string-equal (substring mm 0 3) m))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
570 (throw 'found num))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
571 (setq num (1+ num))))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
572 calendar-month-name-array))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
573 ;; Error:
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
574 -1))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
575
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
576 (defun icalendar--get-weekday-number (abbrevweekday)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
577 "Return the number for the ABBREVWEEKDAY."
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
578 (if abbrevweekday
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
579 (catch 'found
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
580 (let ((num 0)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
581 (aw (downcase abbrevweekday)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
582 (mapc (lambda (day)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
583 (let ((d (downcase day)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
584 (if (string-equal d aw)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
585 (throw 'found num))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
586 (setq num (1+ num))))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
587 icalendar--weekday-array)))
57652
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
588 ;; Error:
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
589 -1))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
590
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
591 (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
592 "Return the abbreviated WEEKDAY."
57652
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
593 (catch 'found
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
594 (let ((num 0)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
595 (w (downcase weekday)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
596 (mapc (lambda (day)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
597 (let ((d (downcase day)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
598 (if (or (string-equal d w)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
599 (string-equal (substring d 0 3) w))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
600 (throw 'found (aref icalendar--weekday-array num)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
601 (setq num (1+ num))))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
602 calendar-day-name-array))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
603 ;; Error:
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
604 nil))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
605
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
606 (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
607 "Convert DATE to iso-style date.
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
608 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
609 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
610 (let ((mdy (calendar-gregorian-from-absolute
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
611 (+ (calendar-absolute-from-gregorian date)
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
612 (or day-shift 0)))))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
613 (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
614
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
615
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
616 (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
617 "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
618 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
619 -- 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
620 takes care of european-style."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
621 (let ((day -1) month year)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
622 (save-match-data
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
623 (cond ( ;; numeric date
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
624 (string-match (concat "\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
625 "0?\\([1-9][0-9]?\\)[ \t/]\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
626 "0?\\([1-9][0-9]?\\),?[ \t/]\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
627 "\\([0-9]\\{4\\}\\)")
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
628 datestring)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
629 (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
630 (match-end 1))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
631 (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
632 (match-end 2))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
633 (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
634 (match-end 3))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
635 (unless european-calendar-style
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
636 (let ((x month))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
637 (setq month day)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
638 (setq day x))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
639 ( ;; date contains month names -- european-style
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
640 (string-match (concat "\\s-*"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
641 "0?\\([123]?[0-9]\\)[ \t/]\\s-*"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
642 "\\([A-Za-z][^ ]+\\)[ \t/]\\s-*"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
643 "\\([0-9]\\{4\\}\\)")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
644 datestring)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
645 (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
646 (match-end 1))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
647 (setq month (icalendar--get-month-number
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
648 (substring datestring (match-beginning 2)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
649 (match-end 2))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
650 (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
651 (match-end 3)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
652 ( ;; date contains month names -- non-european-style
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
653 (string-match (concat "\\s-*"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
654 "\\([A-Za-z][^ ]+\\)[ \t/]\\s-*"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
655 "0?\\([123]?[0-9]\\),?[ \t/]\\s-*"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
656 "\\([0-9]\\{4\\}\\)")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
657 datestring)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
658 (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
659 (match-end 2))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
660 (setq month (icalendar--get-month-number
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
661 (substring datestring (match-beginning 1)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
662 (match-end 1))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
663 (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
664 (match-end 3)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
665 (t
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
666 nil)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
667 (if (> day 0)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
668 (let ((mdy (calendar-gregorian-from-absolute
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
669 (+ (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
670 year))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
671 (or day-shift 0)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
672 (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
673 nil)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
674
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
675 (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
676 "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
677 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
678 would be \"pm\"."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
679 (if timestring
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
680 (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
681 ;; take care of am/pm style
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
682 (if (and ampmstring (string= "pm" ampmstring))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
683 (setq starttimenum (+ starttimenum 1200)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
684 (format "T%04d00" starttimenum))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
685 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
686
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
687 (defun icalendar--convert-string-for-export (string)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
688 "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
689 (icalendar--rris "," "\\\\," string))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
690
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
691 (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
692 "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
693 (icalendar--rris
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
694 "\\\\n" "\n " (icalendar--rris
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
695 "\\\\\"" "\"" (icalendar--rris
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
696 "\\\\;" ";" (icalendar--rris
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
697 "\\\\," "," string)))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
698
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
699 ;; ======================================================================
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
700 ;; 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
701 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
702
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
703 ;;;###autoload
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
704 (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
705 "Export diary file to iCalendar format.
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
706 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
707 format. The result is appended to the file ICAL-FILENAME."
68943
09f294c6700a (icalendar-import-file, icalendar-export-file): Put back significant trailing
Juanma Barranquero <lekktu@gmail.com>
parents: 68930
diff changeset
708 (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
709 Finto iCalendar file: ")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
710 (save-current-buffer
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
711 (set-buffer (find-file diary-filename))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
712 (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
713
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
714 (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
715 (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
716
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
717 ;;;###autoload
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
718 (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
719 "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
720 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
721 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
722 ICAL-FILENAME.
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
723 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
724 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
725 written into the buffer `*icalendar-errors*'."
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
726 (interactive "r
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
727 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
728 (let ((result "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
729 (start 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
730 (entry-main "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
731 (entry-rest "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
732 (header "")
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
733 (contents-n-summary)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
734 (contents)
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
735 (found-error nil)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
736 (nonmarker (concat "^" (regexp-quote diary-nonmarking-symbol)
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
737 "?"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
738 (other-elements nil))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
739 ;; prepare buffer with error messages
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
740 (save-current-buffer
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
741 (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
742 (erase-buffer))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
743
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
744 ;; here we go
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
745 (save-excursion
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
746 (goto-char min)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
747 (while (re-search-forward
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
748 "^\\([^ \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
749 (setq entry-main (match-string 1))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
750 (if (match-beginning 2)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
751 (setq entry-rest (match-string 2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
752 (setq entry-rest ""))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
753 (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
754 (car (current-time))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
755 (cadr (current-time))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
756 (car (cddr (current-time)))))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
757 (condition-case error-val
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
758 (progn
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
759 (setq contents-n-summary
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
760 (icalendar--convert-to-ical nonmarker entry-main))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
761 (setq other-elements (icalendar--parse-summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
762 (concat entry-main entry-rest)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
763 (setq contents (concat (car contents-n-summary)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
764 "\nSUMMARY:" (cadr contents-n-summary)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
765 (let ((cla (cdr (assoc 'cla other-elements)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
766 (des (cdr (assoc 'des other-elements)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
767 (loc (cdr (assoc 'loc other-elements)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
768 (org (cdr (assoc 'org other-elements)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
769 (sta (cdr (assoc 'sta other-elements)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
770 (sum (cdr (assoc 'sum other-elements)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
771 (url (cdr (assoc 'url other-elements))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
772 (if cla
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
773 (setq contents (concat contents "\nCLASS:" cla)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
774 (if des
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
775 (setq contents (concat contents "\nDESCRIPTION:" des)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
776 (if loc
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
777 (setq contents (concat contents "\nLOCATION:" loc)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
778 (if org
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
779 (setq contents (concat contents "\nORGANIZER:" org)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
780 (if sta
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
781 (setq contents (concat contents "\nSTATUS:" sta)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
782 ;;(if sum
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
783 ;; (setq contents (concat contents "\nSUMMARY:" sum)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
784 (if url
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
785 (setq contents (concat contents "\nURL:" url))))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
786 (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
787 ;; handle errors
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
788 (error
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
789 (setq found-error t)
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
790 (save-current-buffer
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
791 (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
792 (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
793 (count-lines (point-min) (point))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
794 (cadr error-val)
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
795 entry-main))))))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
796
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
797 ;; 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
798 (save-current-buffer
60235
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
799 (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
800 (set-buffer (find-file ical-filename))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
801 (goto-char (point-max))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
802 (insert "BEGIN:VCALENDAR")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
803 (insert "\nPRODID:-//Emacs//NONSGML icalendar.el//EN")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
804 (insert "\nVERSION:2.0")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
805 (insert result)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
806 (insert "\nEND:VCALENDAR\n")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
807 ;; save the diary file
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
808 (save-buffer)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
809 (unless found-error
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
810 (bury-buffer)))))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
811 found-error))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
812
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
813 (defun icalendar--convert-to-ical (nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
814 "Convert a diary entry to icalendar format.
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
815 NONMARKER is a regular expression matching the start of non-marking
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
816 entries. ENTRY-MAIN is the first line of the diary entry."
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
817 (or
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
818 ;; anniversaries -- %%(diary-anniversary ...)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
819 (icalendar--convert-anniversary-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
820 ;; cyclic events -- %%(diary-cyclic ...)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
821 (icalendar--convert-cyclic-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
822 ;; diary-date -- %%(diary-date ...)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
823 (icalendar--convert-date-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
824 ;; float events -- %%(diary-float ...)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
825 (icalendar--convert-float-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
826 ;; block events -- %%(diary-block ...)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
827 (icalendar--convert-block-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
828 ;; other sexp diary entries
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
829 (icalendar--convert-sexp-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
830 ;; weekly by day -- Monday 8:30 Team meeting
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
831 (icalendar--convert-weekly-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
832 ;; yearly by day -- 1 May Tag der Arbeit
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
833 (icalendar--convert-yearly-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
834 ;; "ordinary" events, start and end time given
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
835 ;; 1 Feb 2003 blah
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
836 (icalendar--convert-ordinary-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
837 ;; everything else
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
838 ;; Oops! what's that?
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
839 (error "Could not parse entry")))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
840
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
841 (defun icalendar--parse-summary-and-rest (summary-and-rest)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
842 "Parse SUMMARY-AND-REST from a diary to fill iCalendar properties."
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
843 (save-match-data
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
844 (let* ((s icalendar-import-format)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
845 (p-cla (or (string-match "%c" icalendar-import-format) -1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
846 (p-des (or (string-match "%d" icalendar-import-format) -1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
847 (p-loc (or (string-match "%l" icalendar-import-format) -1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
848 (p-org (or (string-match "%o" icalendar-import-format) -1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
849 (p-sum (or (string-match "%s" icalendar-import-format) -1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
850 (p-sta (or (string-match "%t" icalendar-import-format) -1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
851 (p-url (or (string-match "%u" icalendar-import-format) -1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
852 (p-list (sort (list p-cla p-des p-loc p-org p-sta p-sum p-url) '<))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
853 pos-cla pos-des pos-loc pos-org pos-sta pos-sum pos-url)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
854 (dotimes (i (length p-list))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
855 (cond ((and (>= p-cla 0) (= (nth i p-list) p-cla))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
856 (setq pos-cla (+ 2 (* 2 i))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
857 ((and (>= p-des 0) (= (nth i p-list) p-des))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
858 (setq pos-des (+ 2 (* 2 i))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
859 ((and (>= p-loc 0) (= (nth i p-list) p-loc))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
860 (setq pos-loc (+ 2 (* 2 i))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
861 ((and (>= p-org 0) (= (nth i p-list) p-org))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
862 (setq pos-org (+ 2 (* 2 i))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
863 ((and (>= p-sta 0) (= (nth i p-list) p-sta))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
864 (setq pos-sta (+ 2 (* 2 i))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
865 ((and (>= p-sum 0) (= (nth i p-list) p-sum))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
866 (setq pos-sum (+ 2 (* 2 i))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
867 ((and (>= p-url 0) (= (nth i p-list) p-url))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
868 (setq pos-url (+ 2 (* 2 i))))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
869 (mapc (lambda (ij)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
870 (setq s (icalendar--rris (car ij) (cadr ij) s t t)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
871 (list
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
872 ;; summary must be first! because of %s
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
873 (list "%s"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
874 (concat "\\(" icalendar-import-format-summary "\\)?"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
875 (list "%c"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
876 (concat "\\(" icalendar-import-format-class "\\)?"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
877 (list "%d"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
878 (concat "\\(" icalendar-import-format-description "\\)?"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
879 (list "%l"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
880 (concat "\\(" icalendar-import-format-location "\\)?"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
881 (list "%o"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
882 (concat "\\(" icalendar-import-format-organizer "\\)?"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
883 (list "%t"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
884 (concat "\\(" icalendar-import-format-status "\\)?"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
885 (list "%u"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
886 (concat "\\(" icalendar-import-format-url "\\)?"))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
887 (setq s (concat (icalendar--rris "%s" "\\(.*\\)" s nil t) " "))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
888 (if (string-match s summary-and-rest)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
889 (let (cla des loc org sta sum url)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
890 (if (and pos-sum (match-beginning pos-sum))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
891 (setq sum (substring summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
892 (match-beginning pos-sum)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
893 (match-end pos-sum))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
894 (if (and pos-cla (match-beginning pos-cla))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
895 (setq cla (substring summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
896 (match-beginning pos-cla)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
897 (match-end pos-cla))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
898 (if (and pos-des (match-beginning pos-des))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
899 (setq des (substring summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
900 (match-beginning pos-des)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
901 (match-end pos-des))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
902 (if (and pos-loc (match-beginning pos-loc))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
903 (setq loc (substring summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
904 (match-beginning pos-loc)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
905 (match-end pos-loc))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
906 (if (and pos-org (match-beginning pos-org))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
907 (setq org (substring summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
908 (match-beginning pos-org)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
909 (match-end pos-org))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
910 (if (and pos-sta (match-beginning pos-sta))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
911 (setq sta (substring summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
912 (match-beginning pos-sta)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
913 (match-end pos-sta))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
914 (if (and pos-url (match-beginning pos-url))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
915 (setq url (substring summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
916 (match-beginning pos-url)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
917 (match-end pos-url))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
918 (list (if cla (cons 'cla cla) nil)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
919 (if des (cons 'des des) nil)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
920 (if loc (cons 'loc loc) nil)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
921 (if org (cons 'org org) nil)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
922 (if sta (cons 'sta sta) nil)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
923 ;;(if sum (cons 'sum sum) nil)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
924 (if url (cons 'url url) nil)))))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
925
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
926 ;; subroutines for icalendar-export-region
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
927 (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
928 "Convert \"ordinary\" diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
929 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
930 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
931 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
932 "\\([^ /]+[ /]+[^ /]+[ /]+[^ ]+\\)\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
933 "\\(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
934 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
935 "-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
936 "\\)?"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
937 "\\s-*\\(.*?\\) ?$")
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
938 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
939 (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
940 (match-end 1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
941 (startisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
942 datetime))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
943 (endisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
944 datetime 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
945 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
946 (if (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
947 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
948 (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
949 (match-end 3))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
950 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
951 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
952 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
953 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
954 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
955 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
956 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
957 (if (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
958 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
959 (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
960 (match-end 6))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
961 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
962 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
963 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
964 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
965 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
966 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
967 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
968 (substring entry-main (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
969 (match-end 8)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
970 (icalendar--dmsg "ordinary %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
971
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
972 (unless startisostring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
973 (error "Could not parse date"))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
974 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
975 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
976 (let ((time
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
977 (read (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
978 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
979 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
980 (+ 10000 time))))))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
981 (list (concat "\nDTSTART;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
982 (if starttimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
983 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
984 startisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
985 (or starttimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
986 "\nDTEND;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
987 (if endtimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
988 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
989 (if starttimestring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
990 startisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
991 endisostring)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
992 (or endtimestring ""))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
993 summary))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
994 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
995 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
996
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
997 (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
998 "Convert weekly diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
999 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
1000 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
1001 (if (and (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1002 "\\([a-z]+\\)\\s-+"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1003 "\\(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
1004 "\\([ap]m\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1005 "\\(-0?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1006 "\\([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
1007 "\\([ap]m\\)?\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1008 "\\)?"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1009 "\\s-*\\(.*?\\) ?$")
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1010 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1011 (icalendar--get-weekday-abbrev
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1012 (substring entry-main (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1013 (match-end 1))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1014 (let* ((day (icalendar--get-weekday-abbrev
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1015 (substring entry-main (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1016 (match-end 1))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1017 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1018 (if (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1019 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1020 (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1021 (match-end 3))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1022 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1023 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1024 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1025 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1026 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1027 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1028 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1029 (if (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1030 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1031 (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1032 (match-end 6))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1033 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1034 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1035 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1036 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1037 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1038 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1039 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1040 (substring entry-main (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1041 (match-end 8)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1042 (icalendar--dmsg "weekly %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1043
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1044 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1045 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1046 (let ((time (read
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1047 (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1048 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1049 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1050 (+ 10000 time))))))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1051 (list (concat "\nDTSTART;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1052 (if starttimestring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1053 "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1054 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1055 ;; find the correct week day,
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1056 ;; 1st january 2000 was a saturday
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1057 (format
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1058 "200001%02d"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1059 (+ (icalendar--get-weekday-number day) 2))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1060 (or starttimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1061 "\nDTEND;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1062 (if endtimestring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1063 "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1064 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1065 (format
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1066 "200001%02d"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1067 ;; end is non-inclusive!
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1068 (+ (icalendar--get-weekday-number day)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1069 (if endtimestring 2 3)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1070 (or endtimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1071 "\nRRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY="
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1072 day)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1073 summary))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1074 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1075 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1076
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1077 (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
1078 "Convert yearly diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1079 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
1080 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
1081 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1082 (if european-calendar-style
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1083 "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
1084 "\\([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
1085 "\\*?\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1086 "\\(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
1087 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1088 "-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
1089 "\\)?"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1090 "\\s-*\\([^0-9]+.*?\\) ?$" ; must not match years
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1091 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1092 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1093 (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
1094 (monpos (if european-calendar-style 2 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1095 (day (read (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1096 (match-beginning daypos)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1097 (match-end daypos))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1098 (month (icalendar--get-month-number
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1099 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1100 (match-beginning monpos)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1101 (match-end monpos))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1102 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1103 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1104 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1105 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1106 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1107 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1108 (if (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1109 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1110 (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1111 (match-end 5))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1112 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1113 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1114 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1115 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1116 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1117 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1118 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1119 (if (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1120 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1121 (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1122 (match-end 8))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1123 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1124 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1125 (substring entry-main (match-beginning 9)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1126 (match-end 9)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1127 (icalendar--dmsg "yearly %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1128
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1129 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1130 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1131 (let ((time (read
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1132 (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1133 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1134 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1135 (+ 10000 time))))))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1136 (list (concat "\nDTSTART;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1137 (if starttimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1138 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1139 (format "1900%02d%02d" month day)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1140 (or starttimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1141 "\nDTEND;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1142 (if endtimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1143 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1144 ;; end is not included! shift by one day
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1145 (icalendar--date-to-isodate
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1146 (list month day 1900)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1147 (if endtimestring 0 1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1148 (or endtimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1149 "\nRRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH="
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1150 (format "%2d" month)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1151 ";BYMONTHDAY="
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1152 (format "%2d" day))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1153 summary))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1154 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1155 nil))
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 (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
1158 "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
1159
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1160 FIXME!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1161
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1162 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
1163 entries. ENTRY-MAIN is the first line of the diary entry."
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1164 (cond ((string-match (concat nonmarker
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1165 "%%(and \\(([^)]+)\\))\\(\\s-*.*?\\) ?$")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1166 entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1167 ;; simple sexp entry as generated by icalendar.el: strip off the
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1168 ;; unnecessary (and)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1169 (icalendar--dmsg "diary-sexp from icalendar.el %s" entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1170 (icalendar--convert-to-ical
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1171 nonmarker
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1172 (concat "%%"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1173 (substring entry-main (match-beginning 1) (match-end 1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1174 (substring entry-main (match-beginning 2) (match-end 2)))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1175 ((string-match (concat nonmarker
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1176 "%%([^)]+)\\s-*.*")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1177 entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1178 (icalendar--dmsg "diary-sexp %s" entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1179 (error "Sexp-entries are not supported yet"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1180 (t
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1181 ;; no match
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1182 nil)))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1183
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1184 (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
1185 "Convert block diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1186 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
1187 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
1188 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1189 "%%(diary-block \\([^ /]+[ /]+[^ /]+[ /]+[^ ]+\\)"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1190 " +\\([^ /]+[ /]+[^ /]+[ /]+[^ ]+\\))\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1191 "\\(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
1192 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1193 "-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
1194 "\\)?"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1195 "\\s-*\\(.*?\\) ?$")
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1196 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1197 (let* ((startstring (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1198 (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1199 (match-end 1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1200 (endstring (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1201 (match-beginning 2)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1202 (match-end 2)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1203 (startisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1204 startstring))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1205 (endisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1206 endstring))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1207 (endisostring+1 (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1208 endstring 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1209 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1210 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1211 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1212 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1213 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1214 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1215 (if (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1216 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1217 (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1218 (match-end 5))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1219 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1220 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1221 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1222 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1223 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1224 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1225 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1226 (if (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1227 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1228 (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1229 (match-end 8))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1230 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1231 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1232 (substring entry-main (match-beginning 9)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1233 (match-end 9)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1234 (icalendar--dmsg "diary-block %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1235 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1236 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1237 (let ((time
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1238 (read (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1239 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1240 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1241 (+ 10000 time))))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1242 (if starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1243 ;; with time -> write rrule
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1244 (list (concat "\nDTSTART;VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1245 startisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1246 starttimestring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1247 "\nDTEND;VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1248 startisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1249 endtimestring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1250 "\nRRULE:FREQ=DAILY;INTERVAL=1;UNTIL="
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1251 endisostring)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1252 summary)
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1253 ;; no time -> write long event
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1254 (list (concat "\nDTSTART;VALUE=DATE:" startisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1255 "\nDTEND;VALUE=DATE:" endisostring+1)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1256 summary)))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1257 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1258 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1259
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1260 (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
1261 "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
1262
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1263 FIXME!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1264
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1265 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
1266 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
1267 (if (string-match (concat nonmarker
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1268 "%%(diary-float \\([^)]+\\))\\s-*\\(.*?\\) ?$")
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1269 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1270 (progn
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1271 (icalendar--dmsg "diary-float %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1272 (error "`diary-float' is not supported yet"))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1273 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1274 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1275
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1276 (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
1277 "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
1278
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1279 FIXME!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1280
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1281 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
1282 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
1283 (if (string-match (concat nonmarker
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1284 "%%(diary-date \\([^)]+\\))\\s-*\\(.*?\\) ?$")
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1285 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1286 (progn
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1287 (icalendar--dmsg "diary-date %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1288 (error "`diary-date' is not supported yet"))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1289 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1290 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1291
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1292 (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
1293 "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
1294 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
1295 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
1296 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1297 "%%(diary-cyclic \\([^ ]+\\) +"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1298 "\\([^ /]+[ /]+[^ /]+[ /]+[^ ]+\\))\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1299 "\\(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
1300 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1301 "-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
1302 "\\)?"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1303 "\\s-*\\(.*?\\) ?$")
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1304 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1305 (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
1306 (match-end 1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1307 (datetime (substring entry-main (match-beginning 2)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1308 (match-end 2)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1309 (startisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1310 datetime))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1311 (endisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1312 datetime))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1313 (endisostring+1 (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1314 datetime 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1315 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1316 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1317 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1318 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1319 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1320 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1321 (if (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1322 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1323 (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1324 (match-end 5))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1325 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1326 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1327 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1328 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1329 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1330 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1331 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1332 (if (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1333 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1334 (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1335 (match-end 8))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1336 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1337 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1338 (substring entry-main (match-beginning 9)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1339 (match-end 9)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1340 (icalendar--dmsg "diary-cyclic %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1341 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1342 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1343 (let ((time
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1344 (read (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1345 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1346 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1347 (+ 10000 time))))))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1348 (list (concat "\nDTSTART;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1349 (if starttimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1350 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1351 startisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1352 (or starttimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1353 "\nDTEND;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1354 (if endtimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1355 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1356 (if endtimestring endisostring endisostring+1)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1357 (or endtimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1358 "\nRRULE:FREQ=DAILY;INTERVAL=" frequency
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1359 ;; strange: korganizer does not expect
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1360 ;; BYSOMETHING here...
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1361 )
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1362 summary))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1363 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1364 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1365
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1366 (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
1367 "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
1368 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
1369 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
1370 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1371 "%%(diary-anniversary \\([^)]+\\))\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1372 "\\(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
1373 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1374 "-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
1375 "\\)?"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1376 "\\s-*\\(.*?\\) ?$")
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1377 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1378 (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
1379 (match-end 1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1380 (startisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1381 datetime))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1382 (endisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1383 datetime 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1384 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1385 (if (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1386 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1387 (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1388 (match-end 3))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1389 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1390 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1391 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1392 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1393 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1394 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1395 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1396 (if (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1397 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1398 (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1399 (match-end 6))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1400 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1401 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1402 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1403 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1404 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1405 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1406 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1407 (substring entry-main (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1408 (match-end 8)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1409 (icalendar--dmsg "diary-anniversary %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1410 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1411 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1412 (let ((time
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1413 (read (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1414 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1415 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1416 (+ 10000 time))))))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1417 (list (concat "\nDTSTART;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1418 (if starttimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1419 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1420 startisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1421 (or starttimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1422 "\nDTEND;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1423 (if endtimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1424 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1425 endisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1426 (or endtimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1427 "\nRRULE:FREQ=YEARLY;INTERVAL=1"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1428 ;; the following is redundant,
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1429 ;; but korganizer seems to expect this... ;(
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1430 ;; and evolution doesn't understand it... :(
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1431 ;; so... who is wrong?!
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1432 ";BYMONTH="
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1433 (substring startisostring 4 6)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1434 ";BYMONTHDAY="
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1435 (substring startisostring 6 8))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1436 summary))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1437 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1438 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1439
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1440 ;; ======================================================================
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1441 ;; 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
1442 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1443
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
1444 ;;;###autoload
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1445 (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
1446 &optional non-marking)
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1447 "Import an 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
1448 Argument ICAL-FILENAME output iCalendar file.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1449 Argument DIARY-FILENAME input `diary-file'.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1450 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
1451 non-marking or not."
68943
09f294c6700a (icalendar-import-file, icalendar-export-file): Put back significant trailing
Juanma Barranquero <lekktu@gmail.com>
parents: 68930
diff changeset
1452 (interactive "fImport iCalendar data from file:
09f294c6700a (icalendar-import-file, icalendar-export-file): Put back significant trailing
Juanma Barranquero <lekktu@gmail.com>
parents: 68930
diff changeset
1453 Finto diary file:
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1454 p")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1455 ;; clean up the diary file
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1456 (save-current-buffer
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1457 ;; 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
1458 (set-buffer (find-file ical-filename))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1459 (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
1460
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
1461 ;;;###autoload
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1462 (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
1463 non-marking)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1464 "Extract iCalendar events from current buffer.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1465
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1466 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
1467 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
1468 DIARY-FILE.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1469
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1470 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
1471 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
1472 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
1473
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1474 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
1475 non-marking.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1476
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1477 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
1478 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
1479 buffer `*icalendar-errors*'."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1480 (interactive)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1481 (save-current-buffer
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1482 ;; prepare ical
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1483 (message "Preparing icalendar...")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1484 (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
1485 (goto-char (point-min))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1486 (message "Preparing icalendar...done")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1487 (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
1488 (let (ical-contents ical-errors)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1489 ;; read ical
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1490 (message "Reading icalendar...")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1491 (beginning-of-line)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1492 (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
1493 (message "Reading icalendar...done")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1494 ;; convert ical
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1495 (message "Converting icalendar...")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1496 (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
1497 ical-contents
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1498 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
1499 (when diary-file
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1500 ;; 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
1501 (let ((b (find-buffer-visiting diary-file)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1502 (when b
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1503 (save-current-buffer
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1504 (set-buffer b)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1505 (save-buffer)))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1506 (message "Converting icalendar...done")
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1507 ;; return t if no error occured
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1508 (not ical-errors))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1509 (message
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1510 "Current buffer does not contain icalendar contents!")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1511 ;; 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
1512 nil)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1513
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1514 (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
1515 (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
1516
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1517 (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
1518 "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
1519 (let ((string icalendar-import-format)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1520 (conversion-list
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1521 '(("%c" CLASS icalendar-import-format-class)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1522 ("%d" DESCRIPTION icalendar-import-format-description)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1523 ("%l" LOCATION icalendar-import-format-location)
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1524 ("%o" ORGANIZER icalendar-import-format-organizer)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1525 ("%s" SUMMARY icalendar-import-format-summary)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1526 ("%t" STATUS icalendar-import-format-status)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1527 ("%u" URL icalendar-import-format-url))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1528 ;; 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
1529 (mapcar (lambda (i)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1530 (let* ((spec (car i))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1531 (prop (cadr i))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1532 (format (car (cddr i)))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1533 (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
1534 (formatted-contents ""))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1535 (when (and contents (> (length contents) 0))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1536 (setq formatted-contents
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1537 (icalendar--rris "%s"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1538 (icalendar--convert-string-for-import
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1539 contents)
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1540 (symbol-value format)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1541 t t)))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1542 (setq string (icalendar--rris spec
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1543 formatted-contents
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1544 string
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1545 t t))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1546 conversion-list)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1547 string))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1548
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1549 (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
1550 &optional do-not-ask
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1551 non-marking)
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1552 "Convert Calendar data to an Emacs diary file.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1553 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
1554 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
1555 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
1556 events are created as non-marking.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1557 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
1558 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
1559 written into the buffer `*icalendar-errors*'."
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1560 (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
1561 (error-string "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1562 (event-ok t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1563 (found-error nil)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1564 e diary-string)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1565 ;; step through all events/appointments
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1566 (while ev
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1567 (setq e (car ev))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1568 (setq ev (cdr ev))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1569 (setq event-ok nil)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1570 (condition-case error-val
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1571 (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
1572 (dtstart-dec (icalendar--decode-isodatetime dtstart))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1573 (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
1574 dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1575 (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
1576 (dtend (icalendar--get-event-property e 'DTEND))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1577 (dtend-dec (icalendar--decode-isodatetime dtend))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1578 (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
1579 end-d
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1580 end-1-d
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1581 end-t
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1582 (summary (icalendar--convert-string-for-import
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1583 (or (icalendar--get-event-property e 'SUMMARY)
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1584 "No summary")))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1585 (rrule (icalendar--get-event-property e 'RRULE))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1586 (rdate (icalendar--get-event-property e 'RDATE))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1587 (duration (icalendar--get-event-property e 'DURATION)))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1588 (icalendar--dmsg "%s: `%s'" start-d summary)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1589 ;; check whether start-time is missing
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1590 (if (and dtstart
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1591 (string=
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1592 (cadr (icalendar--get-event-property-attributes
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1593 e 'DTSTART))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1594 "DATE"))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1595 (setq start-t nil))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1596 (when duration
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1597 (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
1598 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1599 (icalendar--decode-isoduration duration)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1600 (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
1601 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1602 (icalendar--decode-isoduration duration
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1603 t))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1604 (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
1605 (message "Inconsistent endtime and duration for %s"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1606 summary))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1607 (setq dtend-dec dtend-dec-d)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1608 (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
1609 (setq end-d (if dtend-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1610 (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
1611 start-d))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1612 (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
1613 (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
1614 start-d))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1615 (setq end-t (if (and
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1616 dtend-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1617 (not (string=
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1618 (cadr
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1619 (icalendar--get-event-property-attributes
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1620 e 'DTEND))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1621 "DATE")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1622 (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
1623 start-t))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1624 (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
1625 (cond
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1626 ;; recurring event
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1627 (rrule
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1628 (setq diary-string
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1629 (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
1630 end-t))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1631 (setq event-ok t))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1632 (rdate
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1633 (icalendar--dmsg "rdate event")
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1634 (setq diary-string "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1635 (mapcar (lambda (datestring)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1636 (setq diary-string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1637 (concat diary-string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1638 (format "......"))))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1639 (icalendar--split-value rdate)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1640 ;; non-recurring event
60235
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
1641 ;; all-day event
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1642 ((not (string= start-d end-d))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1643 (setq diary-string
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1644 (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
1645 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
1646 (setq event-ok t))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1647 ;; not all-day
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1648 ((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
1649 (not (string= start-t end-t))))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1650 (setq diary-string
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1651 (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
1652 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
1653 (setq event-ok t))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1654 ;; all-day event
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1655 (t
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1656 (icalendar--dmsg "all day event")
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1657 (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
1658 dtstart-dec "/"))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1659 (setq event-ok t)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1660 ;; 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
1661 ;; them
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1662 (if event-ok
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1663 (progn
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1664 (setq diary-string
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1665 (concat diary-string " "
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1666 (icalendar--format-ical-event e)))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1667 (if do-not-ask (setq summary nil))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1668 (icalendar--add-diary-entry diary-string diary-file
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1669 non-marking summary))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1670 ;; event was not ok
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1671 (setq found-error t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1672 (setq error-string
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1673 (format "%s\nCannot handle this event:%s"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1674 error-string e))))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1675 ;; 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
1676 ;; handle errors
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1677 (error
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1678 (message "Ignoring event \"%s\"" e)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1679 (setq found-error t)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1680 (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
1681 error-val error-string e))
65591
a65f8ec418fc message format spec fixes, commit # 10
Deepak Goel <deego@gnufans.org>
parents: 64432
diff changeset
1682 (message "%s" error-string))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1683 (if found-error
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1684 (save-current-buffer
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1685 (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
1686 (erase-buffer)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1687 (insert error-string)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1688 (message "Converting icalendar...done")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1689 found-error))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1690
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1691 ;; subroutines for importing
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1692 (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
1693 "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
1694
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1695 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
1696 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
1697 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
1698 (icalendar--dmsg "recurring event")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1699 (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
1700 (rrule-props (icalendar--split-value rrule))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1701 (frequency (cadr (assoc 'FREQ rrule-props)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1702 (until (cadr (assoc 'UNTIL rrule-props)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1703 (count (cadr (assoc 'COUNT rrule-props)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1704 (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
1705 (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
1706 (until-conv (icalendar--datetime-to-diary-date
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1707 (icalendar--decode-isodatetime until)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1708 (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
1709 (icalendar--decode-isodatetime until -1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1710 (result ""))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1711
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1712 ;; FIXME FIXME interval!!!!!!!!!!!!!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1713
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1714 (when count
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1715 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1716 (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
1717 (let ((until-1 0))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1718 (cond ((string-equal frequency "DAILY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1719 (setq until (icalendar--add-decoded-times
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1720 dtstart-dec
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1721 (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
1722 (setq until-1 (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1723 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1724 (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
1725 0 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1726 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1727 ((string-equal frequency "WEEKLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1728 (setq until (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1729 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1730 (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
1731 (setq until-1 (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1732 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1733 (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
1734 interval) 0 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1735 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1736 ((string-equal frequency "MONTHLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1737 (setq until (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1738 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
1739 interval) 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1740 (setq until-1 (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1741 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
1742 interval) 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1743 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1744 ((string-equal frequency "YEARLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1745 (setq until (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1746 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
1747 interval))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1748 (setq until-1 (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1749 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1750 (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
1751 interval))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1752 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1753 (t
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1754 (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
1755 frequency)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1756 (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
1757 (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
1758 ))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1759 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1760 (cond ((string-equal frequency "WEEKLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1761 (if (not start-t)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1762 (progn
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1763 ;; weekly and all-day
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1764 (icalendar--dmsg "weekly all-day")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1765 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1766 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1767 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1768 (concat "%%%%(and "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1769 "(diary-cyclic %d %s) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1770 "(diary-block %s %s))")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1771 (* interval 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1772 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1773 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1774 (if count until-1-conv until-conv)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1775 ))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1776 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1777 (format "%%%%(and (diary-cyclic %d %s))"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1778 (* interval 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1779 dtstart-conv))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1780 ;; weekly and not all-day
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1781 (let* ((byday (cadr (assoc 'BYDAY rrule-props)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1782 (weekday
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1783 (icalendar--get-weekday-number byday)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1784 (icalendar--dmsg "weekly not-all-day")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1785 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1786 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1787 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1788 (concat "%%%%(and "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1789 "(diary-cyclic %d %s) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1790 "(diary-block %s %s)) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1791 "%s%s%s")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1792 (* interval 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1793 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1794 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1795 until-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1796 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1797 (if end-t "-" "") (or end-t "")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1798 ;; no limit
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1799 ;; FIXME!!!!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1800 ;; DTSTART;VALUE=DATE-TIME:20030919T090000
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1801 ;; DTEND;VALUE=DATE-TIME:20030919T113000
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1802 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1803 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1804 "%%%%(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
1805 (* interval 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1806 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1807 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1808 (if end-t "-" "") (or end-t "")))))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1809 ;; yearly
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1810 ((string-equal frequency "YEARLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1811 (icalendar--dmsg "yearly")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1812 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1813 (setq result (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1814 (concat "%%%%(and (diary-date %s %s t) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1815 "(diary-block %s %s)) %s%s%s")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1816 (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
1817 (nth 4 dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1818 (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
1819 (nth 3 dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1820 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1821 until-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1822 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1823 (if end-t "-" "") (or end-t "")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1824 (setq result (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1825 "%%%%(and (diary-anniversary %s)) %s%s%s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1826 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1827 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1828 (if end-t "-" "") (or end-t "")))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1829 ;; monthly
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1830 ((string-equal frequency "MONTHLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1831 (icalendar--dmsg "monthly")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1832 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1833 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1834 "%%%%(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
1835 (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
1836 (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
1837 "t"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1838 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1839 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1840 until-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1841 "1 1 9999") ;; FIXME: should be unlimited
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1842 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1843 (if end-t "-" "") (or end-t ""))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1844 ;; daily
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1845 ((and (string-equal frequency "DAILY"))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1846 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1847 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1848 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1849 (concat "%%%%(and (diary-cyclic %s %s) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1850 "(diary-block %s %s)) %s%s%s")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1851 interval dtstart-conv dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1852 (if count until-1-conv until-conv)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1853 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1854 (if end-t "-" "") (or end-t "")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1855 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1856 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1857 "%%%%(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
1858 interval
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1859 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1860 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1861 (if end-t "-" "") (or end-t ""))))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1862 ;; Handle exceptions from recurrence rules
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1863 (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
1864 (while ex-dates
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1865 (let* ((ex-start (icalendar--decode-isodatetime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1866 (car ex-dates)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1867 (ex-d (icalendar--datetime-to-diary-date
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1868 ex-start)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1869 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1870 (icalendar--rris "^%%(\\(and \\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1871 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1872 "%%%%(and (not (diary-date %s)) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1873 ex-d)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1874 result)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1875 (setq ex-dates (cdr ex-dates))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1876 ;; FIXME: exception rules are not recognized
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1877 (if (icalendar--get-event-property e 'EXRULE)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1878 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1879 (concat result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1880 "\n Exception rules: "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1881 (icalendar--get-event-properties
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1882 e 'EXRULE))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1883 result))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1884
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1885 (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
1886 "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
1887
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1888 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
1889 Argument START-D gives the first day.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1890 Argument END-D gives the last day."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1891 (icalendar--dmsg "non-recurring all-day event")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1892 (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
1893
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1894 (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
1895 dtend-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1896 start-t
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1897 end-t)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1898 "Convert recurring icalendar EVENT to diary format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1899
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1900 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
1901 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
1902 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
1903 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
1904 (icalendar--dmsg "not all day event")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1905 (cond (end-t
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1906 (format "%s %s-%s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1907 (icalendar--datetime-to-diary-date
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1908 dtstart-dec "/")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1909 start-t end-t))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1910 (t
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1911 (format "%s %s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1912 (icalendar--datetime-to-diary-date
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1913 dtstart-dec "/")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1914 start-t))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1915
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1916 (defun icalendar--add-diary-entry (string diary-file non-marking
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1917 &optional summary)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1918 "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
1919 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
1920 determines whether diary events are created as non-marking. If
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1921 SUMMARY is not nil it must be a string that gives the summary of the
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1922 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
1923 the entry."
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1924 (when (or (not summary)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1925 (y-or-n-p (format "Add appointment for `%s' to diary? "
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1926 summary)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1927 (when summary
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1928 (setq non-marking
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1929 (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
1930 (save-window-excursion
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1931 (unless diary-file
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1932 (setq diary-file
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1933 (read-file-name "Add appointment to this diary file: ")))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1934 ;; Note: make-diary-entry will add a trailing blank char.... :(
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1935 (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
1936
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1937 (provide 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1938
57345
f024640dc5e4 Changes from arch/CVS synchronization
Miles Bader <miles@gnu.org>
parents: 57337
diff changeset
1939 ;; 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
1940 ;;; icalendar.el ends here