annotate lisp/calendar/icalendar.el @ 92408:a371504924ef

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