Add support for UNTIL in recurrences
Change-Id: I983e1bcb209e794b462ec43efaccefe95bf9bd9d
diff --git a/src/com/android/exchange/utility/CalendarUtilities.java b/src/com/android/exchange/utility/CalendarUtilities.java
index e9945b7..7360c50 100644
--- a/src/com/android/exchange/utility/CalendarUtilities.java
+++ b/src/com/android/exchange/utility/CalendarUtilities.java
@@ -584,6 +584,40 @@
}
/**
+ * Reformat an RRULE style UNTIL to an EAS style until
+ */
+ static String recurrenceUntilToEasUntil(String until) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(until.substring(0, 4));
+ sb.append('-');
+ sb.append(until.substring(4, 6));
+ sb.append('-');
+ if (until.length() == 8) {
+ sb.append(until.substring(6, 8));
+ sb.append("T00:00:00");
+
+ } else {
+ sb.append(until.substring(6, 11));
+ sb.append(':');
+ sb.append(until.substring(11, 13));
+ sb.append(':');
+ sb.append(until.substring(13, 15));
+ }
+ sb.append(".000Z");
+ return sb.toString();
+ }
+
+ /**
+ * Convenience method to add "until" to an EAS calendar stream
+ */
+ static void addUntil(String rrule, Serializer s) throws IOException {
+ String until = tokenFromRrule(rrule, "UNTIL=");
+ if (until != null) {
+ s.data(Tags.CALENDAR_RECURRENCE_UNTIL, recurrenceUntilToEasUntil(until));
+ }
+ }
+
+ /**
* Write recurrence information to EAS based on the RRULE in CalendarProvider
* @param rrule the RRULE, from CalendarProvider
* @param startTime, the DTSTART of this Event
@@ -615,6 +649,7 @@
if (byDay != null) {
s.data(Tags.CALENDAR_RECURRENCE_DAYOFWEEK, generateEasDayOfWeek(byDay));
}
+ addUntil(rrule, s);
s.end();
} else if (freq.equals("MONTHLY")) {
String byMonthDay = tokenFromRrule(rrule, "BYMONTHDAY=");
@@ -623,6 +658,7 @@
s.start(Tags.CALENDAR_RECURRENCE);
s.data(Tags.CALENDAR_RECURRENCE_TYPE, "2");
s.data(Tags.CALENDAR_RECURRENCE_DAYOFMONTH, byMonthDay);
+ addUntil(rrule, s);
s.end();
} else {
String byDay = tokenFromRrule(rrule, "BYDAY=");
@@ -642,6 +678,7 @@
s.data(Tags.CALENDAR_RECURRENCE_TYPE, "3");
s.data(Tags.CALENDAR_RECURRENCE_WEEKOFMONTH, Integer.toString(wom));
s.data(Tags.CALENDAR_RECURRENCE_DAYOFWEEK, generateEasDayOfWeek(bareByDay));
+ addUntil(rrule, s);
s.end();
}
}
@@ -660,6 +697,7 @@
s.data(Tags.CALENDAR_RECURRENCE_TYPE, "5");
s.data(Tags.CALENDAR_RECURRENCE_DAYOFMONTH, byMonthDay);
s.data(Tags.CALENDAR_RECURRENCE_MONTHOFYEAR, byMonth);
+ addUntil(rrule, s);
s.end();
}
}
@@ -717,10 +755,8 @@
}
// UNTIL comes last
- // TODO Add UNTIL code
if (until != null) {
- // *** until probably needs reformatting
- //rrule.append(";UNTIL=" + until);
+ rrule.append(";UNTIL=" + until);
}
return rrule.toString();
diff --git a/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java b/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java
index cb97e86..6437309 100644
--- a/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java
+++ b/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java
@@ -92,6 +92,16 @@
assertNull(CalendarUtilities.tokenFromRrule(rrule, "UNTIL="));
}
+ public void testRecurrenceUntilToEasUntil() {
+ // Test full format
+ assertEquals("YYYY-MM-DDTHH:MM:SS.000Z",
+ CalendarUtilities.recurrenceUntilToEasUntil("YYYYMMDDTHHMMSSZ"));
+ // Test date only format
+ assertEquals("YYYY-MM-DDT00:00:00.000Z",
+ CalendarUtilities.recurrenceUntilToEasUntil("YYYYMMDD"));
+ }
+
+
// Tests in progress...
// public void testTimeZoneToTziString() {