fix marker scaling in freq display

This commit is contained in:
eduebernal
2022-07-05 21:41:27 -07:00
parent 36ee39589e
commit a6180a5049
2 changed files with 27 additions and 3 deletions

View File

@@ -19,6 +19,7 @@
package org.isoron.uhabits.core.utils
import org.isoron.uhabits.core.models.Timestamp
import java.time.YearMonth
import java.util.Calendar
import java.util.Calendar.DAY_OF_MONTH
import java.util.Calendar.DAY_OF_WEEK
@@ -178,6 +179,26 @@ abstract class DateUtils {
return getWeekdayNames(GregorianCalendar.SHORT, firstWeekday)
}
/**
* Returns a vector of Int representing the frequency of each weekday in a given month.
*
* @param startOfMonth a Timestamp representing the beginning of the month.
*/
@JvmStatic
fun getWeekdaysInMonth(startOfMonth: Timestamp): Array<Int> {
val month = startOfMonth.toCalendar()[Calendar.MONTH] + 1
val year = startOfMonth.toCalendar()[Calendar.YEAR]
val weekday = startOfMonth.weekday
val extraWeekdays = YearMonth.of(year, month).lengthOfMonth() - 28
val freq = Array(7) { 4 }
for (day in weekday until weekday + extraWeekdays) {
freq[day % 7] = 5
}
return freq
}
@JvmStatic
fun getToday(): Timestamp = Timestamp(getStartOfToday())