Fix monthly recurrence at end of month

pull/1702/head
Alex Baker 3 years ago
parent 23f12c8df3
commit 024183f118

@ -125,7 +125,7 @@ class RepeatTaskHelper @Inject constructor(
private fun handleMonthlyRepeat(
original: DateTime, startDateAsDV: Date, hasDueTime: Boolean, recur: Recur): Long {
return if (original.isLastDayOfMonth) {
val interval = recur.interval
val interval = recur.interval.coerceAtLeast(1)
val newDateTime = original.plusMonths(interval)
val time = newDateTime.withDayOfMonth(newDateTime.numberOfDaysInMonth).millis
if (hasDueTime) {

@ -56,6 +56,30 @@ class RepeatMonthlyTests : RepeatTests() {
assertEquals(newDayTime(2017, 2, 28, 13, 30), next)
}
@Test
fun repeatMonthlyNoInterval() {
val task = newFromDue(
"FREQ=MONTHLY",
newDayTime(2017, 11, 1, 13, 30)
)
val next = calculateNextDueDate(task)
assertEquals(newDayTime(2017, 12, 1, 13, 30), next)
}
@Test
fun repeatMonthlyEndOfMonthNoInterval() {
val task = newFromDue(
"FREQ=MONTHLY",
newDayTime(2017, 11, 30, 13, 30)
)
val next = calculateNextDueDate(task)
assertEquals(newDayTime(2017, 12, 31, 13, 30), next)
}
/* https://tools.ietf.org/html/rfc5545#section-3.3.10
* Recurrence rules may generate recurrence instances with an invalid
* date (e.g., February 30) or nonexistent local time (e.g., 1:30 AM

Loading…
Cancel
Save