fun YearMonth.getNumberWeeks(weekFields: WeekFields = CALENDAR_STARTS_ON): Int { val firstWeekNumber = this.atDay(1)[weekFields.weekOfMonth()] val lastWeekNumber = this.atEndOfMonth()[weekFields.weekOfMonth()] return lastWeekNumber - firstWeekNumber + 1 // Both weeks inclusive }
This function get the number of weeks in the month