From 2955c4e02046c419f0a50dc79f21cc3a6652dccf Mon Sep 17 00:00:00 2001 From: Hafiz Date: Thu, 5 Jun 2025 14:10:50 -0500 Subject: [PATCH] Fixes incorrect week calculation for monthly repeats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using the built-in "week of month" value meant that any days before the 1st counted as “week 1,” so selecting the first Monday sometimes grabbed a date that actually belonged to a partial week from the previous month. The new approach replaces that by taking the numeric day (1-31) and grouping 1-7 as week 1, 8–14 as week 2, and so on - so "first Monday" really means the first Monday falling in days 1–7 of that month, not a stray day from a partial week. --- .../habitica/ui/views/tasks/form/TaskSchedulingControls.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/tasks/form/TaskSchedulingControls.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/tasks/form/TaskSchedulingControls.kt index 09f09ef57..cbf5180bc 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/tasks/form/TaskSchedulingControls.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/tasks/form/TaskSchedulingControls.kt @@ -199,8 +199,11 @@ constructor( weeksOfMonth = null generateSummary() } + binding.monthlyRepeatWeeks.setOnClickListener { - weeksOfMonth = mutableListOf(startDateCalendar.get(Calendar.WEEK_OF_MONTH) - 1) + val dayOfMonth = startDateCalendar.get(Calendar.DAY_OF_MONTH) + val zeroBasedWeekIdx = (dayOfMonth - 1) / 7 + weeksOfMonth = mutableListOf(zeroBasedWeekIdx) daysOfMonth = null generateSummary() }