maltaisn / recurpickerlib

Recurrence picker fragment and dialog for Android, with utilities for finding recurrence dates
Apache License 2.0
65 stars 16 forks source link

Computation error in `findRecurrences`? #24

Closed guger closed 5 years ago

guger commented 5 years ago

Why does recurrence.findRecurrences(1558821600001, 1) return 1558821600000?

maltaisn commented 5 years ago

What are the recurrence rules? This is probably a bug.

guger commented 5 years ago

Just daily.

maltaisn commented 5 years ago

I didn't manage to reproduce your output. What was the start date of the recurrence and in what time zone?

guger commented 5 years ago
@Test
fun testDailyRecurrences() {
    val recurrence = Recurrence(LocalDate.now().minusDays(5).atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli(), Recurrence.DAILY)

    val missedRecurrences = recurrence.findRecurrencesBetween(0, System.currentTimeMillis())

    assertThat(missedRecurrences, notNullValue())

    val nextRecurrence = recurrence.findRecurrences(System.currentTimeMillis().inc(), 1).first()

    assertThat(nextRecurrence, notNullValue())
    assertThat(missedRecurrences.size, `is`(5))
    assertNotEquals("lastRecurrence: ${missedRecurrences.last()} - nextRecurrence $nextRecurrence", missedRecurrences.last(), nextRecurrence)
}
maltaisn commented 5 years ago

Thanks, I fixed it.

This is actually a kind of problem I feared would happen since the library was developed with more focus on UI than on the recurrence computation system, which should actually have been done by another library made for that. But I didn't find any at the time. So I made one that's "good enough", without a lot of testing, since recurring events is often a secondary feature in apps anyway.

guger commented 5 years ago

Well, therefore I'm testing :)

Your libs are great, I'm using all three dialogs in my app now ;D