diff --git a/app/src/main/java/at/bitfire/davdroid/DateUtils.java b/app/src/main/java/at/bitfire/davdroid/DateUtils.java new file mode 100644 index 00000000..94309c84 --- /dev/null +++ b/app/src/main/java/at/bitfire/davdroid/DateUtils.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013 – 2015 Ricki Hirner (bitfire web engineering). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + */ + +package at.bitfire.davdroid; + +import android.text.format.Time; +import android.util.Log; + +import org.apache.commons.lang.StringUtils; + +import java.util.SimpleTimeZone; + +public class DateUtils { + private final static String TAG = "davdroid.DateUtils"; + + public static String findAndroidTimezoneID(String tzID) { + String localTZ = null; + String availableTZs[] = SimpleTimeZone.getAvailableIDs(); + + // first, try to find an exact match (case insensitive) + for (String availableTZ : availableTZs) + if (tzID.equalsIgnoreCase(availableTZ)) { + localTZ = availableTZ; + break; + } + + // if that doesn't work, try to find something else that matches + if (localTZ == null) { + Log.w(TAG, "Coulnd't find time zone with matching identifiers, trying to guess"); + for (String availableTZ : availableTZs) + if (StringUtils.indexOfIgnoreCase(tzID, availableTZ) != -1) { + localTZ = availableTZ; + break; + } + } + + // if that doesn't work, use UTC as fallback + if (localTZ == null) { + Log.e(TAG, "Couldn't identify time zone, using UTC as fallback"); + localTZ = Time.TIMEZONE_UTC; + } + + Log.d(TAG, "Assuming time zone " + localTZ + " for " + tzID); + return localTZ; + } +} diff --git a/app/src/main/java/at/bitfire/davdroid/resource/Event.java b/app/src/main/java/at/bitfire/davdroid/resource/Event.java index c64709d7..0ed016b8 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/Event.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/Event.java @@ -66,6 +66,7 @@ import java.util.SimpleTimeZone; import java.util.TimeZone; import at.bitfire.davdroid.Constants; +import at.bitfire.davdroid.DateUtils; import at.bitfire.davdroid.syncadapter.DavSyncAdapter; import lombok.Getter; import lombok.NonNull; @@ -408,33 +409,7 @@ public class Event extends Resource { if (tzID == null) return; - String localTZ = null; - String availableTZs[] = SimpleTimeZone.getAvailableIDs(); - - // first, try to find an exact match (case insensitive) - for (String availableTZ : availableTZs) - if (tzID.equalsIgnoreCase(availableTZ)) { - localTZ = availableTZ; - break; - } - - // if that doesn't work, try to find something else that matches - if (localTZ == null) { - Log.w(TAG, "Coulnd't find time zone with matching identifiers, trying to guess"); - for (String availableTZ : availableTZs) - if (StringUtils.indexOfIgnoreCase(tzID, availableTZ) != -1) { - localTZ = availableTZ; - break; - } - } - - // if that doesn't work, use UTC as fallback - if (localTZ == null) { - Log.e(TAG, "Couldn't identify time zone, using UTC as fallback"); - localTZ = Time.TIMEZONE_UTC; - } - - Log.d(TAG, "Assuming time zone " + localTZ + " for " + tzID); + String localTZ = DateUtils.findAndroidTimezoneID(tzID); date.setTimeZone(tzRegistry.getTimeZone(localTZ)); } diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java index 92b48023..70b20662 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java @@ -68,6 +68,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import at.bitfire.davdroid.DateUtils; import lombok.Cleanup; import lombok.Getter; @@ -576,7 +577,12 @@ public class LocalCalendar extends LocalCollection { } if (event.getRdate() != null) { recurring = true; - builder = builder.withValue(Events.RDATE, event.getRdate().getValue()); + RDate rDate = event.getRdate(); + String rDateStr = event.getRdate().getValue(); + if (rDate.getTimeZone() != null) + rDateStr = DateUtils.findAndroidTimezoneID(rDate.getTimeZone().getID()) + ";" + rDateStr; + Log.i(TAG, "Setting RDate in DB: " + rDateStr); + builder = builder.withValue(Events.RDATE, rDateStr); } if (event.getExrule() != null) builder = builder.withValue(Events.EXRULE, event.getExrule().getValue());