From 0afea3ac3901d06a9b19a445339cae7c2eee7fa1 Mon Sep 17 00:00:00 2001 From: Varsha-29 Date: Fri, 31 Jul 2020 08:02:41 +0530 Subject: [PATCH] Fixes #1170 Contact birthday not correct on changing timezone The birthday was captured in DB with current time zone. While retrieving the date was parsed based on the current time zone. Modified that logic to parse date based on the timezone at which it was originally captured --- .../com/simplemobiletools/calendar/pro/helpers/Formatter.kt | 2 ++ .../calendar/pro/helpers/MonthlyCalendarImpl.kt | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Formatter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Formatter.kt index e24ffcf82..543cf9b96 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Formatter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Formatter.kt @@ -85,6 +85,8 @@ object Formatter { fun getDateTimeFromTS(ts: Long) = DateTime(ts * 1000L, DateTimeZone.getDefault()) + fun getDateTimeFromTSForATimeZone(ts: Long, timeZoneId: String) = DateTime(ts * 1000L, DateTimeZone.forID(timeZoneId)) + fun getUTCDateTimeFromTS(ts: Long) = DateTime(ts * 1000L, DateTimeZone.UTC) // use manually translated month names, as DateFormat and Joda have issues with a lot of languages diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MonthlyCalendarImpl.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MonthlyCalendarImpl.kt index bb5f68c7f..0a358be61 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MonthlyCalendarImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MonthlyCalendarImpl.kt @@ -84,8 +84,8 @@ class MonthlyCalendarImpl(val callback: MonthlyCalendar, val context: Context) { private fun markDaysWithEvents(days: ArrayList) { val dayEvents = HashMap>() mEvents.forEach { - val startDateTime = Formatter.getDateTimeFromTS(it.startTS) - val endDateTime = Formatter.getDateTimeFromTS(it.endTS) + val startDateTime = Formatter.getDateTimeFromTSForATimeZone(it.startTS, it.timeZone) + val endDateTime = Formatter.getDateTimeFromTSForATimeZone(it.endTS, it.timeZone) val endCode = Formatter.getDayCodeFromDateTime(endDateTime) var currDay = startDateTime