From 37bc2698715d2cd3986b057dcb322184ed4ba68e Mon Sep 17 00:00:00 2001 From: Tim <86524864+WessellUrdata@users.noreply.github.com> Date: Sun, 14 May 2023 21:09:20 +0800 Subject: [PATCH] fixed getDatesWeekDateTime --- .../calendar/pro/extensions/Context.kt | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt index ad7a1f3e8..6169270ec 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt @@ -765,19 +765,20 @@ fun Context.editEvent(event: ListEvent) { } fun Context.getDatesWeekDateTime(date: DateTime): String { - return if (!config.startWeekWithCurrentDay) { - val currentOffsetHours = TimeZone.getDefault().rawOffset / 1000 / 60 / 60 - - // not great, not terrible - val useHours = if (currentOffsetHours >= 10) 8 else 12 - var thisweek = date.withZone(DateTimeZone.UTC).withDayOfWeek(1).withHourOfDay(useHours).minusDays(if (config.isSundayFirst) 1 else 0) - if (date.minusDays(7).seconds() > thisweek.seconds()) { - thisweek = thisweek.plusDays(7) + var startOfWeek = date.withZoneRetainFields(DateTimeZone.UTC).withTimeAtStartOfDay() + if (!config.startWeekWithCurrentDay) { + startOfWeek = if (config.isSundayFirst) { + // a workaround for Joda-time's Monday-as-first-day-of-the-week + if (startOfWeek.dayOfWeek == 7) { + startOfWeek + } else { + startOfWeek.minusWeeks(1).withDayOfWeek(7) + } + } else { + startOfWeek.withDayOfWeek(1) } - thisweek.toString() - } else { - date.withZone(DateTimeZone.UTC).toString() } + return startOfWeek.toString() } fun Context.isTaskCompleted(event: Event): Boolean {