Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
emacs
emacs
Commits
16b5f507
Commit
16b5f507
authored
Nov 17, 2014
by
Ulf Jasper
Browse files
New option `icalendar-export-alarms'.
parent
b7cce56d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
128 additions
and
22 deletions
+128
-22
lisp/ChangeLog
lisp/ChangeLog
+9
-0
lisp/calendar/icalendar.el
lisp/calendar/icalendar.el
+17
-11
test/ChangeLog
test/ChangeLog
+8
-0
test/automated/icalendar-tests.el
test/automated/icalendar-tests.el
+94
-11
No files found.
lisp/ChangeLog
View file @
16b5f507
2014-11-17 Ulf Jasper <ulf.jasper@web.de>
* calendar/icalendar.el (icalendar-export-alarms): New
customizable variable.
(icalendar-export-region): Export alarms as specified in
`icalendar-export-alarms'.
(icalendar--create-ical-alarm, icalendar--do-create-ical-alarm):
New functions for exporting alarms.
2014-11-16 Ulf Jasper <ulf.jasper@web.de>
* calendar/icalendar.el (icalendar--convert-tz-offset): Return
...
...
lisp/calendar/icalendar.el
View file @
16b5f507
...
...
@@ -270,8 +270,7 @@ other sexp entries are enumerated in any case."
(
defcustom
icalendar-export-alarms
nil
"Determine if and how alarms are included in exported diary events.
FIXME"
"Determine if and how alarms are included in exported diary events."
:version
"25.1"
:type
'
(
choice
(
const
:tag
"Do not include alarms in export"
nil
)
...
...
@@ -304,7 +303,6 @@ FIXME"
;; ======================================================================
(
require
'calendar
)
(
require
'diary-lib
)
(
require
'appt
)
;; ======================================================================
;; misc
...
...
@@ -1115,7 +1113,7 @@ FExport diary data into iCalendar file: ")
(icalendar--create-uid
entry-full contents))))
(setq alarm (icalendar--create-ical-alarm
(c
a
r contents-n-summary))))
(c
d
r contents-n-summary))))
(setq result (concat result header contents alarm
"
\nEND:VEVENT
")))
(if (consp cns-cons-or-list)
...
...
@@ -1292,33 +1290,41 @@ Returns an alist."
(if uid (cons 'uid uid) nil))))))))
(defun icalendar--create-ical-alarm (summary)
"
Return
VALARM
blocks
for
the
given
SUMMARY.
"
(when icalendar-export-alarms
(let* ((advance-time (car icalendar-export-alarms))
(alarm-specs (cadr icalendar-export-alarms))
(fun (lambda (spec)
(icalendar--do-create-ical-alarm advance-time spec summary))))
(mapconcat fun alarm-specs "
\n
"))))
(mapconcat fun alarm-specs ""))))
(defun icalendar--do-create-ical-alarm (advance-time alarm-spec summary)
"
Return
a
VALARM
block.
Argument
ADVANCE-TIME
is
a
number
giving
the
time
when
the
alarm
fires
(
minutes
before
the
respective
event
)
.
Argument
ALARM-SPEC
is
a
list
which
must
be
one
of
'
(
audio
)
,
'
(
display
)
or
'
(
email
(
ADDRESS1
...
))
,
see
`
icalendar-export-alarms
'.
Argument
SUMMARY
is
a
string
which
contains
a
short
description
for
the
alarm.
"
(let* ((action (car alarm-spec))
(act (format "
ACTION:%s
\n
"
(act (format "
\n
ACTION:%s
"
(cdr (assoc action '((audio . "
AUDIO
")
(display . "
DISPLAY
")
(email . "
EMAIL
"))))))
(tri (format "
TRIGGER:-PT%dM
\n
" advance-time))
(tri (format "
\n
TRIGGER:-PT%dM
" advance-time))
(des (if (memq action '(display email))
(format "
DESCRIPTION:%s
\n
" summary)
(format "
\n
DESCRIPTION:%s
" summary)
""))
(sum (if (eq action 'email)
(format "
SUMMARY:%s
\n
" summary)
(format "
\n
SUMMARY:%s
" summary)
""))
(att (if (eq action 'email)
(mapconcat (lambda (i)
(format "
ATTENDEE:MAILTO:%s
\n
" i))
(format "
\n
ATTENDEE:MAILTO:%s
" i))
(cadr alarm-spec) "")
"")))
(concat "
BEGIN:VALARM
\n
" act tri des sum att "
END:VALARM
")))
(concat "
\n
BEGIN:VALARM
" act tri des sum att "
\n
END:VALARM
")))
;; subroutines for icalendar-export-region
(defun icalendar--convert-ordinary-to-ical (nonmarker entry-main)
...
...
test/ChangeLog
View file @
16b5f507
2014-11-17 Ulf Jasper <ulf.jasper@web.de>
* automated/icalendar-tests.el (icalendar-tests--test-export): New
optional parameter `alarms'.
(icalendar-export-alarms): New test for exporting icalendar
alarms.
(icalendar-tests--test-cycle): Let `icalendar-export-alarms' be nil.
2014-11-16 Ulf Jasper <ulf.jasper@web.de>
* automated/icalendar-tests.el (icalendar--parse-vtimezone): Add
...
...
test/automated/icalendar-tests.el
View file @
16b5f507
...
...
@@ -503,33 +503,25 @@ END:VEVENT
;; restore time-zone even if something went terribly wrong
(
setenv
"TZ"
tz
)))
)
(
ert-deftest
icalendar--create-ical-alarm
()
"Test `icalendar--create-ical-alarms'."
(
let
((
icalendar-export-alarms
))
;; testcase: no alarms
(
setq
icalendar-export-alarm
nil
)
(
should
(
equal
nil
(
icalendar--create-ical-alarm
"sumsum"
)))))
;; ======================================================================
;; Export tests
;; ======================================================================
(
defun
icalendar-tests--test-export
(
input-iso
input-european
input-american
expected-output
)
expected-output
&optional
alarms
)
"Perform an export test.
Argument INPUT-ISO iso style diary string.
Argument INPUT-EUROPEAN european style diary string.
Argument INPUT-AMERICAN american style diary string.
Argument EXPECTED-OUTPUT expected iCalendar result string.
Optional argument ALARMS the value of `icalendar-export-alarms' for this test.
European style input data must use german month names. American
and ISO style input data must use english month names."
(
let
((
tz
(
getenv
"TZ"
))
(
calendar-date-style
'iso
)
(
icalendar-recurring-start-year
2000
)
(
icalendar-export-alarms
nil
))
(
icalendar-export-alarms
alarms
))
(
unwind-protect
(
progn
;;; (message "Current time zone: %s" (current-time-zone))
...
...
@@ -763,6 +755,97 @@ RRULE:FREQ=DAILY;INTERVAL=1;UNTIL=20010706
SUMMARY:block no end time
"
))
(
ert-deftest
icalendar-export-alarms
()
"Perform export test with different settings for exporting alarms."
;; no alarm
(
icalendar-tests--test-export
"2014 Nov 17 19:30 no alarm"
"17 Nov 2014 19:30 no alarm"
"Nov 17 2014 19:30 no alarm"
"DTSTART;VALUE=DATE-TIME:20141117T193000
DTEND;VALUE=DATE-TIME:20141117T203000
SUMMARY:no alarm
"
nil
)
;; 10 minutes in advance, audio
(
icalendar-tests--test-export
"2014 Nov 17 19:30 audio alarm"
"17 Nov 2014 19:30 audio alarm"
"Nov 17 2014 19:30 audio alarm"
"DTSTART;VALUE=DATE-TIME:20141117T193000
DTEND;VALUE=DATE-TIME:20141117T203000
SUMMARY:audio alarm
BEGIN:VALARM
ACTION:AUDIO
TRIGGER:-PT10M
END:VALARM
"
'
(
10
((
audio
))))
;; 20 minutes in advance, display
(
icalendar-tests--test-export
"2014 Nov 17 19:30 display alarm"
"17 Nov 2014 19:30 display alarm"
"Nov 17 2014 19:30 display alarm"
"DTSTART;VALUE=DATE-TIME:20141117T193000
DTEND;VALUE=DATE-TIME:20141117T203000
SUMMARY:display alarm
BEGIN:VALARM
ACTION:DISPLAY
TRIGGER:-PT20M
DESCRIPTION:display alarm
END:VALARM
"
'
(
20
((
display
))))
;; 66 minutes in advance, email
(
icalendar-tests--test-export
"2014 Nov 17 19:30 email alarm"
"17 Nov 2014 19:30 email alarm"
"Nov 17 2014 19:30 email alarm"
"DTSTART;VALUE=DATE-TIME:20141117T193000
DTEND;VALUE=DATE-TIME:20141117T203000
SUMMARY:email alarm
BEGIN:VALARM
ACTION:EMAIL
TRIGGER:-PT66M
DESCRIPTION:email alarm
SUMMARY:email alarm
ATTENDEE:MAILTO:att.one@email.com
ATTENDEE:MAILTO:att.two@email.com
END:VALARM
"
'
(
66
((
email
(
"att.one@email.com"
"att.two@email.com"
)))))
;; 2 minutes in advance, all alarms
(
icalendar-tests--test-export
"2014 Nov 17 19:30 all alarms"
"17 Nov 2014 19:30 all alarms"
"Nov 17 2014 19:30 all alarms"
"DTSTART;VALUE=DATE-TIME:20141117T193000
DTEND;VALUE=DATE-TIME:20141117T203000
SUMMARY:all alarms
BEGIN:VALARM
ACTION:EMAIL
TRIGGER:-PT2M
DESCRIPTION:all alarms
SUMMARY:all alarms
ATTENDEE:MAILTO:att.one@email.com
ATTENDEE:MAILTO:att.two@email.com
END:VALARM
BEGIN:VALARM
ACTION:AUDIO
TRIGGER:-PT2M
END:VALARM
BEGIN:VALARM
ACTION:DISPLAY
TRIGGER:-PT2M
DESCRIPTION:all alarms
END:VALARM
"
'
(
2
((
email
(
"att.one@email.com"
"att.two@email.com"
))
(
audio
)
(
display
)))))
;; ======================================================================
;; Import tests
;; ======================================================================
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment