mirror of
https://github.com/etesync/android
synced 2024-12-23 23:18:46 +00:00
parent
5e9fe92520
commit
c707b1eb9d
51
app/src/main/java/at/bitfire/davdroid/DateUtils.java
Normal file
51
app/src/main/java/at/bitfire/davdroid/DateUtils.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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<Event> {
|
||||
}
|
||||
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());
|
||||
|
Loading…
Reference in New Issue
Block a user