-
Notifications
You must be signed in to change notification settings - Fork 44
Examples
Contents
Parsing an iCalendar file
Creating an iCalendar file
Creating an all-day event
Cancelling an event
Formatting dates under a Timezone
Calculating the dates in a recurring event
Parsing an RRULE string
//using Biweekly
File file = ...
List<ICalendar> icals = Biweekly.parse(file).all();
//using ICalReader
File file = ...
ICalReader reader = null;
try {
reader = new ICalReader(file);
ICalendar ical;
while ((ical = reader.readNext()) != null){
...
}
} finally {
if (reader != null) reader.close();
}
ICalendar ical = new ICalendar();
VEvent event = new VEvent();
event.setSummary("the summary");
...
ical.addEvent(event);
//using Biweekly
File file = ...
Biweekly.write(ical).go(file);
//using ICalWriter
File file = ...
ICalWriter writer = null;
try {
writer = new ICalWriter(file);
writer.write(ical);
} finally {
if (writer != null) writer.close();
}
VEvent event = new VEvent();
Date start = ...
event.setDateStart(start, false);
ICalendar ical = new ICalendar();
ical.setMethod("CANCEL");
VEvent event = new VEvent();
event.setOrganizer("jdoe@example.com"); //the organizer of the existing event
event.setUid(...); //the UID of the existing event
event.setSequence(2); //increment the sequence number of the existing event
event.addComment(...); //optional: describe why it was cancelled
ical.addEvent(event);
By default, biweekly writes all date/time values in UTC time, but this can be changed. See Timezones for more information on how to work with timezones.
TimeZone javaTz = TimeZone.getTimeZone("America/New_York");
TimezoneAssignment newYork = TimezoneAssignment.download(javaTz, false);
ICalendar ical = ...
ical.getTimezoneInfo().setDefaultTimezone(newYork);
File file = ...
ICalWriter writer = null;
try {
writer = new ICalWriter(file);
writer.write(ical);
} finally {
if (writer != null) writer.close();
}
ICalendar ical = ...
TimezoneInfo tzinfo = ical.getTimezoneInfo();
VEvent event = ical.getEvents().get(0);
DateStart dtstart = event.getDateStart();
TimeZone timezone;
if (tzinfo.isFloating(dtstart)){
timezone = TimeZone.getDefault();
} else {
TimezoneAssignment dtstartTimezone = tzinfo.getTimezone(dtstart);
timezone = (dtstartTimezone == null) ? TimeZone.getTimeZone("UTC") : dtstartTimezone.getTimeZone();
}
DateIterator it = event.getDateIterator(timezone);
RecurrenceRuleScribe scribe = new RecurrenceRuleScribe();
ParseContext context = new ParseContext();
context.setVersion(ICalVersion.V2_0);
RecurrenceRule rrule = scribe.parseText("FREQ=WEEKLY;INTERVAL=2", null, new ICalParameters(), context);
Recurrence recur = rrule.getValue();
Date start = ...
TimeZone timezone = ...
DateIterator it = rrule.getDateIterator(start, timezone);
while (it.hasNext()) {
System.out.println(it.next());
}
biweekly is maintained by Michael Angstadt
Table of Contents
Getting started
Examples
FAQ
Javadocs
Downloads
1 An Overview of the iCalendar data format
2 Reading and Writing iCalendar data with biweekly
2.1 Plain-text (traditional)
2.2 XML-encoded (xCal)
2.3 JSON-encoded (jCal)
4 Working with Timezones
4.1 0.4.6 and earlier
4.2 0.5.0 and later
5 Dealing with Non-standard Data
5.1 Non-standard components
5.2 Non-standard properties
5.3 Non-standard parameters
6 Project Information
6.1 Dependencies
6.2 Supported Specifications
6.3 Changelog
7 Reference
7.1 iCalendar Component Reference
7.2 iCalendar Property Reference
7.3 Javadocs