From c444c476b3b97a541e6564054afa87e2bb26044a Mon Sep 17 00:00:00 2001 From: Naveen Date: Thu, 20 Oct 2022 23:43:42 +0530 Subject: [PATCH] Use UTC timezone when creating all day events Related issues: https://github.com/SimpleMobileTools/Simple-Calendar/issues/1539 https://github.com/SimpleMobileTools/Simple-Calendar/issues/1480 --- .../calendar/pro/activities/EventActivity.kt | 20 +++++++++++++++---- .../calendar/pro/helpers/CalDAVHelper.kt | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt index a22aaf7ce..e9d11fa60 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt @@ -224,9 +224,14 @@ class EventActivity : SimpleActivity() { updateTextColors(event_scrollview) updateIconColors() refreshMenuItems() - event_time_zone_divider.beVisibleIf(config.allowChangingTimeZones) - event_time_zone_image.beVisibleIf(config.allowChangingTimeZones) - event_time_zone.beVisibleIf(config.allowChangingTimeZones) + showOrHideTimeZone() + } + + private fun showOrHideTimeZone() { + val allowChangingTimeZones = config.allowChangingTimeZones && !event_all_day.isChecked + event_time_zone_divider.beVisibleIf(allowChangingTimeZones) + event_time_zone_image.beVisibleIf(allowChangingTimeZones) + event_time_zone.beVisibleIf(allowChangingTimeZones) } private fun refreshMenuItems() { @@ -998,6 +1003,9 @@ class EventActivity : SimpleActivity() { hideKeyboard() event_start_time.beGoneIf(isChecked) event_end_time.beGoneIf(isChecked) + mEvent.timeZone = if (isChecked) DateTimeZone.UTC.id else DateTimeZone.getDefault().id + updateTimeZoneText() + showOrHideTimeZone() resetTime() } @@ -1149,7 +1157,11 @@ class EventActivity : SimpleActivity() { reminder3Type = mReminder3Type repeatInterval = mRepeatInterval importId = newImportId - timeZone = if (mEvent.timeZone.isEmpty()) TimeZone.getDefault().id else timeZone + timeZone = when { + mIsAllDayEvent -> DateTimeZone.UTC.id + timeZone.isEmpty() -> DateTimeZone.getDefault().id + else -> timeZone + } flags = mEvent.flags.addBitIf(event_all_day.isChecked, FLAG_ALL_DAY) repeatLimit = if (repeatInterval == 0) 0 else mRepeatLimit repeatRule = mRepeatRule diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt index 2f4a4de4f..d597c4b33 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt @@ -228,8 +228,8 @@ class CalDAVHelper(val context: Context) { val event = Event( null, startTS, endTS, title, location, description, reminder1?.minutes ?: REMINDER_OFF, reminder2?.minutes ?: REMINDER_OFF, reminder3?.minutes ?: REMINDER_OFF, reminder1?.type - ?: REMINDER_NOTIFICATION, reminder2?.type ?: REMINDER_NOTIFICATION, reminder3?.type - ?: REMINDER_NOTIFICATION, repeatRule.repeatInterval, repeatRule.repeatRule, + ?: REMINDER_NOTIFICATION, reminder2?.type ?: REMINDER_NOTIFICATION, reminder3?.type + ?: REMINDER_NOTIFICATION, repeatRule.repeatInterval, repeatRule.repeatRule, repeatRule.repeatLimit, ArrayList(), attendees, importId, eventTimeZone, allDay, eventTypeId, source = source, availability = availability )