Merge pull request #1318 from ikazuhiro/support-29-feb-yearly-event

support 29th Feb. yearly recurring events
This commit is contained in:
Tibor Kaputa 2021-03-22 11:58:30 +01:00 committed by GitHub
commit 19a5d6f7ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -54,7 +54,7 @@ data class Event(
repeatInterval % YEAR == 0 -> when (repeatRule) {
REPEAT_ORDER_WEEKDAY -> addXthDayInterval(oldStart, original, false)
REPEAT_ORDER_WEEKDAY_USE_LAST -> addXthDayInterval(oldStart, original, true)
else -> oldStart.plusYears(repeatInterval / YEAR)
else -> addYearsWithSameDay(oldStart)
}
repeatInterval % MONTH == 0 -> when (repeatRule) {
REPEAT_SAME_DAY -> addMonthsWithSameDay(oldStart, original)
@ -77,6 +77,20 @@ data class Event(
endTS = newEndTS
}
// if an event should happen on 29th Feb. with Same Day yearly repetition, show it only on leap years
private fun addYearsWithSameDay(currStart: DateTime): DateTime {
var newDateTime = currStart.plusYears(repeatInterval / YEAR)
// Date may slide within the same month
if (newDateTime.dayOfMonth != currStart.dayOfMonth) {
while (newDateTime.dayOfMonth().maximumValue < currStart.dayOfMonth) {
newDateTime = newDateTime.plusYears(repeatInterval / YEAR)
}
newDateTime = newDateTime.withDayOfMonth(currStart.dayOfMonth)
}
return newDateTime
}
// if an event should happen on 31st with Same Day monthly repetition, dont show it at all at months with 30 or less days
private fun addMonthsWithSameDay(currStart: DateTime, original: Event): DateTime {
var newDateTime = currStart.plusMonths(repeatInterval / MONTH)