Add Custom Week Number Calculation Support #309
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Custom Week Number Calculation Support
Hi there 👋
Thanks for taking the time to review this pull request. I've implemented support for custom week number calculation to address the needs of applications using non-standard calendar systems (academic calendars, fiscal years, etc.).
Related Issue
This PR addresses the feature request in Issue #308 #294 - Support for Custom Week Number Calculation
Overview of Changes
Core Feature Implementation
I've added the ability to customize week number calculation through a new
beginWeekCalendarproperty inWeekView. This allows applications to specify a custom start date for week numbering, which is particularly useful for:Key Classes Modified
WeekView.kt
beginWeekCalendarproperty with@PublicApiannotationCalendarobject representing the custom start dateHeaderRendererfor week number calculationHeaderRenderer.kt
beginWeekCalendarparameterdrawWeekNumber()methodbeginWeekCalendaris setImplementation Details
The week number calculation works as follows:
beginWeekCalendaris null: Uses standard ISO week numbering (current behavior)beginWeekCalendaris set: Calculates the number of weeks between the custom start date and the current displayed dateAPI Compatibility Improvements
Initially implemented with Java 8 time API (Instant, LocalDateTime, ChronoUnit), but refactored to use the standard Calendar API to ensure compatibility with older Android versions (pre-API 26). This eliminates the need for
@RequiresApiannotations and makes the feature available to all users.Screenshots
Before (Standard Week Numbering)
Week numbers start from January 1st following ISO standard.
After (Custom Week Numbering)
When
beginWeekCalendaris set to September 1st, week numbers start from that date:Testing
beginWeekCalendaris nullAdditional Notes
beginWeekCalendarpropertyThank you for considering this contribution! I'm happy to make any adjustments based on your feedback.