Merge pull request #369 from angelsl/master

Fix all-day CalDAV event import for local TZ > GMT+5
This commit is contained in:
Tibor Kaputa 2018-02-18 19:55:00 +01:00 committed by GitHub
commit a58cda96d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 15 deletions

View file

@ -234,18 +234,6 @@ class CalDAVHandler(val context: Context) {
val originalInstanceTime = cursor.getLongValue(CalendarContract.Events.ORIGINAL_INSTANCE_TIME)
val reminders = getCalDAVEventReminders(id)
// make sure all-day events start at 5am in the users timezone
if (allDay == 1 && timeZone == "UTC") {
val offset = DateTimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000
val FIVE_HOURS = 5 * 60 * 60
startTS -= offset
startTS += FIVE_HOURS
if (endTS != 0) {
endTS -= offset
endTS += FIVE_HOURS
}
}
if (endTS == 0) {
val duration = cursor.getStringValue(CalendarContract.Events.DURATION) ?: ""
endTS = startTS + Parser().parseDurationSeconds(duration)
@ -258,10 +246,12 @@ class CalDAVHandler(val context: Context) {
reminders.getOrElse(1, { -1 }), reminders.getOrElse(2, { -1 }), repeatRule.repeatInterval,
importId, allDay, repeatRule.repeatLimit, repeatRule.repeatRule, eventTypeId, source = source, location = location)
if (event.getIsAllDay() && endTS > startTS) {
if (event.getIsAllDay()) {
event.startTS = Formatter.getShiftedImportTimestamp(event.startTS)
event.endTS = Formatter.getShiftedImportTimestamp(event.endTS)
event.endTS -= DAY
if (event.endTS > event.startTS) {
event.endTS -= DAY
}
}
fetchedEventIds.add(importId)

View file

@ -100,5 +100,5 @@ object Formatter {
"0"
}
fun getShiftedImportTimestamp(ts: Int) = getDateTimeFromTS(ts).toDateTime(DateTimeZone.UTC).withZoneRetainFields(DateTimeZone.getDefault()).withTime(5, 0, 0, 0).seconds()
fun getShiftedImportTimestamp(ts: Int) = getDateTimeFromTS(ts).withTime(5, 0, 0, 0).seconds()
}