Merge pull request #2077 from WessellUrdata/sunday-fix

Fixing getDatesWeekDateTime (closes Issue #1894)
This commit is contained in:
Tibor Kaputa 2023-06-29 12:45:42 +02:00 committed by GitHub
commit 5f856d7164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 11 deletions

View File

@ -766,19 +766,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 {