Improve automatic checkmarks for monthly habits

Fixes #947
This commit is contained in:
2021-06-05 16:54:13 -05:00
parent 2163a2b93b
commit 33468bfc1c
7 changed files with 62 additions and 61 deletions

View File

@@ -72,6 +72,13 @@ data class LocalDate(val daysSince2000: Int) {
return dayCache
}
val monthLength: Int
get() = when (month) {
4, 6, 9, 11 -> 30
2 -> if (isLeapYear(year)) 29 else 28
else -> 31
}
private fun updateYearMonthDayCache() {
var currYear = 2000
var currDay = 0

View File

@@ -248,8 +248,17 @@ open class EntryList {
for (i in num - 1 until filtered.size) {
val (begin, _) = filtered[i]
val (center, _) = filtered[i - num + 1]
if (begin.daysUntil(center) < den) {
val end = begin.plus(den - 1)
var size = den
if (den == 30 || den == 31) {
val beginDate = begin.toLocalDate()
size = if (beginDate.day == beginDate.monthLength) {
beginDate.plus(1).monthLength
} else {
beginDate.monthLength
}
}
if (begin.daysUntil(center) < size) {
val end = begin.plus(size - 1)
intervals.add(Interval(begin, center, end))
}
}