From 5074861f3f0b3218414523731625f1c8e4579601 Mon Sep 17 00:00:00 2001 From: angelsl Date: Mon, 19 Feb 2018 00:57:54 +0800 Subject: [PATCH] Fix all-day CalDAV event import for local TZ > GMT+5 --- .../calendar/helpers/CalDAVHandler.kt | 18 ++++-------------- .../calendar/helpers/Formatter.kt | 2 +- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVHandler.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVHandler.kt index a1c0d9983..c987e0668 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVHandler.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVHandler.kt @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Formatter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Formatter.kt index 40787ef80..65533fdf2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Formatter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Formatter.kt @@ -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() }