Use local timezone to configure weekly views
This addresses issues like https://github.com/SimpleMobileTools/Simple-Calendar/issues/2143 The weekly view originally used local timezone to configure everything but was modified to use UTC to fix a `Start week with Sunday` issue https://github.com/SimpleMobileTools/Simple-Calendar/issues/1213 where events were created on the wrong day. Since `getFirstDayOfWeek()` was rewritten to handle week preferences properly, there is no need to complicate things using UTC anymore (otherwise we'll have to handle UTC-to-local-timezone conversion in many places) This also fixes an issue with the drag-and-drop feature where the events were moved by ±1 day because the difference in timezone was not taken care of.
This commit is contained in:
parent
acc35f791e
commit
2ee226d06b
|
@ -20,7 +20,6 @@ import android.provider.CalendarContract
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.Toast
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.app.AlarmManagerCompat
|
||||
import androidx.core.app.NotificationCompat
|
||||
|
@ -48,7 +47,6 @@ import com.simplemobiletools.commons.helpers.*
|
|||
import kotlinx.android.synthetic.main.day_monthly_event_view.view.*
|
||||
import org.joda.time.DateTime
|
||||
import org.joda.time.DateTimeConstants
|
||||
import org.joda.time.DateTimeZone
|
||||
import org.joda.time.LocalDate
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
|
@ -327,7 +325,8 @@ fun Context.notifyEvent(originalEvent: Event) {
|
|||
val events = eventsHelper.getRepeatableEventsFor(currentSeconds - WEEK_SECONDS, currentSeconds + YEAR_SECONDS, event.id!!)
|
||||
for (currEvent in events) {
|
||||
eventStartTS = if (currEvent.getIsAllDay()) Formatter.getDayStartTS(Formatter.getDayCodeFromTS(currEvent.startTS)) else currEvent.startTS
|
||||
val firstReminderMinutes = arrayOf(currEvent.reminder3Minutes, currEvent.reminder2Minutes, currEvent.reminder1Minutes).filter { it != REMINDER_OFF }.max()
|
||||
val firstReminderMinutes =
|
||||
arrayOf(currEvent.reminder3Minutes, currEvent.reminder2Minutes, currEvent.reminder1Minutes).filter { it != REMINDER_OFF }.max()
|
||||
if (eventStartTS - firstReminderMinutes * 60 > currentSeconds) {
|
||||
break
|
||||
}
|
||||
|
@ -759,7 +758,7 @@ fun Context.editEvent(event: ListEvent) {
|
|||
}
|
||||
|
||||
fun Context.getFirstDayOfWeek(date: DateTime): String {
|
||||
var startOfWeek = date.withZoneRetainFields(DateTimeZone.UTC).withTimeAtStartOfDay()
|
||||
var startOfWeek = date.withTimeAtStartOfDay()
|
||||
if (!config.startWeekWithCurrentDay) {
|
||||
startOfWeek = if (config.isSundayFirst) {
|
||||
// a workaround for Joda-time's Monday-as-first-day-of-the-week
|
||||
|
|
|
@ -196,14 +196,14 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
mView.week_events_columns_holder.removeAllViews()
|
||||
(0 until config.weeklyViewDays).forEach {
|
||||
val column = inflater.inflate(R.layout.weekly_view_day_column, mView.week_events_columns_holder, false) as RelativeLayout
|
||||
column.tag = Formatter.getUTCDayCodeFromTS(weekTimestamp + it * DAY_SECONDS)
|
||||
column.tag = Formatter.getDayCodeFromTS(weekTimestamp + it * DAY_SECONDS)
|
||||
mView.week_events_columns_holder.addView(column)
|
||||
dayColumns.add(column)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupDayLabels() {
|
||||
var curDay = Formatter.getUTCDateTimeFromTS(weekTimestamp)
|
||||
var curDay = Formatter.getDateTimeFromTS(weekTimestamp)
|
||||
val todayCode = Formatter.getDayCodeFromDateTime(DateTime())
|
||||
val screenWidth = context?.usableScreenSize?.x ?: return
|
||||
val dayWidth = screenWidth / config.weeklyViewDays
|
||||
|
|
|
@ -311,7 +311,7 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
|
|||
|
||||
override fun getCurrentDate(): DateTime? {
|
||||
return if (currentWeekTS != 0L) {
|
||||
Formatter.getUTCDateTimeFromTS(currentWeekTS)
|
||||
Formatter.getDateTimeFromTS(currentWeekTS)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue