calendar: fix displaying recurring event frequency in details page
- Commit
d7436b5084eca90809aea2969b1a3af6819f96d9- Author
- Vayun Mathur <[email protected]>
- When
- 2026-07-16 17:56 UTC (4 months ago)
- Parents
a4a5931
Diff
calendar/src/main/java/com/vayunmathur/calendar/util/RRule.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/util/RRule.kt b/calendar/src/main/java/com/vayunmathur/calendar/util/RRule.ktindex a103fef364..5589ffd12b 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/util/RRule.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/util/RRule.kt@@ -53,7 +53,7 @@ sealed class RRule { abstract val byWeekNo: List<Int>? abstract val wkst: DayOfWeek? abstract fun asString(firstDay: LocalDate, timeZone: TimeZone): String- override fun toString(): String {+ final override fun toString(): String { return toStringImpl() + endCondition.toStringSuffix() } protected abstract fun toStringImpl(): String@@ -169,7 +169,7 @@ sealed class RRule { val base = "FREQ=YEARLY;INTERVAL=$years" return buildRRuleString(base, timeZone) }- override fun toStringImpl(): String = "Every $years years"+ override fun toStringImpl(): String = if (years == 1) "Yearly" else "Every $years years" } @Serializable@@ -193,7 +193,7 @@ sealed class RRule { } else "" return buildRRuleString(base + byDayPart, timeZone) }- override fun toStringImpl(): String = "Every $months months"+ override fun toStringImpl(): String = if (months == 1) "Monthly" else "Every $months months" } @Serializable@@ -213,9 +213,14 @@ sealed class RRule { val base = "FREQ=WEEKLY;INTERVAL=$weeks;BYDAY=$days" return buildRRuleString(base, timeZone) }- override fun toStringImpl(): String = "Every $weeks weeks on ${- daysOfWeek.joinToString(", ") { it.name.take(3).lowercase().replaceFirstChar { c -> c.titlecase() } }- }"+ override fun toStringImpl(): String {+ val prefix = if (weeks == 1) "Weekly" else "Every $weeks weeks"+ if (daysOfWeek.isEmpty()) return prefix+ val days = daysOfWeek.sorted().joinToString(", ") {+ it.name.take(3).lowercase().replaceFirstChar { c -> c.titlecase() }+ }+ return "$prefix on $days"+ } } @Serializable@@ -233,6 +238,6 @@ sealed class RRule { val base = "FREQ=DAILY;INTERVAL=$days" return buildRRuleString(base, timeZone) }- override fun toStringImpl(): String = "Every $days days"+ override fun toStringImpl(): String = if (days == 1) "Daily" else "Every $days days" } }\ No newline at end of file
calendar/src/test/java/com/vayunmathur/calendar/util/RRuleTest.kt
diff --git a/calendar/src/test/java/com/vayunmathur/calendar/util/RRuleTest.kt b/calendar/src/test/java/com/vayunmathur/calendar/util/RRuleTest.ktindex cc1e6f1e59..08e8e23e81 100644--- a/calendar/src/test/java/com/vayunmathur/calendar/util/RRuleTest.kt+++ b/calendar/src/test/java/com/vayunmathur/calendar/util/RRuleTest.kt@@ -10,6 +10,30 @@ class RRuleTest { private val timeZone = TimeZone.of("America/Los_Angeles") + @Test+ fun readableStringUsesReadableFormNotDataClass() {+ val yearly = RRule.parse("FREQ=YEARLY;INTERVAL=1", timeZone)!!+ assertEquals("Yearly", yearly.toString())++ val everyThreeYears = RRule.parse("FREQ=YEARLY;INTERVAL=3", timeZone)!!+ assertEquals("Every 3 years", everyThreeYears.toString())++ val monthly = RRule.parse("FREQ=MONTHLY;INTERVAL=1", timeZone)!!+ assertEquals("Monthly", monthly.toString())++ val daily = RRule.parse("FREQ=DAILY;INTERVAL=1", timeZone)!!+ assertEquals("Daily", daily.toString())++ val weekly = RRule.parse("FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,WE", timeZone)!!+ assertEquals("Weekly on Mon, Wed", weekly.toString())+ }++ @Test+ fun readableStringIncludesEndCondition() {+ val counted = RRule.parse("FREQ=DAILY;INTERVAL=2;COUNT=5", timeZone)!!+ assertEquals("Every 2 days, 5 times", counted.toString())+ }+ @Test fun testParseDailyWithInterval() { val rrule = RRule.parse("FREQ=DAILY;INTERVAL=2", timeZone)