protected static String getTzId(DateProperty date) { if (date.isUtc() || !hasTime(date)) return Time.TIMEZONE_UTC; else if (date.getTimeZone() != null) return date.getTimeZone().getID(); else if (date.getParameter(Value.TZID) != null) return date.getParameter(Value.TZID).getValue(); // fallback return Time.TIMEZONE_UTC; }
/* guess matching Android timezone ID */ protected static void validateTimeZone(DateProperty date) { if (date.isUtc() || !hasTime(date)) return; String tzID = getTzId(date); if (tzID == null) return; String localTZ = Time.TIMEZONE_UTC; String availableTZs[] = SimpleTimeZone.getAvailableIDs(); for (String availableTZ : availableTZs) if (tzID.indexOf(availableTZ, 0) != -1) { localTZ = availableTZ; break; } Log.d(TAG, "Assuming time zone " + localTZ + " for " + tzID); date.setTimeZone(tzRegistry.getTimeZone(localTZ)); }
protected static boolean hasTime(DateProperty date) { return date.getDate() instanceof DateTime; }