1
0
mirror of https://github.com/etesync/android synced 2024-12-24 15:38:09 +00:00

RDATE processing

* don't ignore the time zone of RDATEs (see #340)
This commit is contained in:
Ricki Hirner 2015-05-02 11:39:25 +02:00
parent 5e9fe92520
commit c707b1eb9d
3 changed files with 60 additions and 28 deletions

View File

@ -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;
}
}

View File

@ -66,6 +66,7 @@ import java.util.SimpleTimeZone;
import java.util.TimeZone; import java.util.TimeZone;
import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.Constants;
import at.bitfire.davdroid.DateUtils;
import at.bitfire.davdroid.syncadapter.DavSyncAdapter; import at.bitfire.davdroid.syncadapter.DavSyncAdapter;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
@ -408,33 +409,7 @@ public class Event extends Resource {
if (tzID == null) if (tzID == null)
return; return;
String localTZ = null; String localTZ = DateUtils.findAndroidTimezoneID(tzID);
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);
date.setTimeZone(tzRegistry.getTimeZone(localTZ)); date.setTimeZone(tzRegistry.getTimeZone(localTZ));
} }

View File

@ -68,6 +68,7 @@ import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import at.bitfire.davdroid.DateUtils;
import lombok.Cleanup; import lombok.Cleanup;
import lombok.Getter; import lombok.Getter;
@ -576,7 +577,12 @@ public class LocalCalendar extends LocalCollection<Event> {
} }
if (event.getRdate() != null) { if (event.getRdate() != null) {
recurring = true; 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) if (event.getExrule() != null)
builder = builder.withValue(Events.EXRULE, event.getExrule().getValue()); builder = builder.withValue(Events.EXRULE, event.getExrule().getValue());