fixed getDatesWeekDateTime

This commit is contained in:
Tim 2023-05-14 21:09:20 +08:00
parent dea55ca94c
commit 37bc269871
1 changed files with 12 additions and 11 deletions

View File

@ -765,19 +765,20 @@ fun Context.editEvent(event: ListEvent) {
} }
fun Context.getDatesWeekDateTime(date: DateTime): String { fun Context.getDatesWeekDateTime(date: DateTime): String {
return if (!config.startWeekWithCurrentDay) { var startOfWeek = date.withZoneRetainFields(DateTimeZone.UTC).withTimeAtStartOfDay()
val currentOffsetHours = TimeZone.getDefault().rawOffset / 1000 / 60 / 60 if (!config.startWeekWithCurrentDay) {
startOfWeek = if (config.isSundayFirst) {
// not great, not terrible // a workaround for Joda-time's Monday-as-first-day-of-the-week
val useHours = if (currentOffsetHours >= 10) 8 else 12 if (startOfWeek.dayOfWeek == 7) {
var thisweek = date.withZone(DateTimeZone.UTC).withDayOfWeek(1).withHourOfDay(useHours).minusDays(if (config.isSundayFirst) 1 else 0) startOfWeek
if (date.minusDays(7).seconds() > thisweek.seconds()) {
thisweek = thisweek.plusDays(7)
}
thisweek.toString()
} else { } else {
date.withZone(DateTimeZone.UTC).toString() startOfWeek.minusWeeks(1).withDayOfWeek(7)
} }
} else {
startOfWeek.withDayOfWeek(1)
}
}
return startOfWeek.toString()
} }
fun Context.isTaskCompleted(event: Event): Boolean { fun Context.isTaskCompleted(event: Event): Boolean {