- Notifications
You must be signed in to change notification settings - Fork 898
Description
Bug description
Starting from week 14 in 2026, every week is offset by 1, see picture below where week 13 appears twice.
The same problem probably exists in the calendar widget as well since it uses the same code.
Steps to reproduce
Enable week number in datepicker :)
Code sample
Code sample
SfDateRangePicker( minDate: DateTime.now().subtract(const Duration(days: 5000)), maxDate: DateTime.now().add(const Duration(days: 5000)), enableMultiView: false, selectionMode: DateRangePickerSelectionMode.single, view: DateRangePickerView.month, monthViewSettings: DateRangePickerMonthViewSettings( showWeekNumber: true, firstDayOfWeek: 1, dayFormat: 'EEE', weekNumberStyle: DateRangePickerWeekNumberStyle( backgroundColor: widget.isOnCard == true ? containerColor(context) : Theme.of(context).colorScheme.surface, textStyle: TextStyle( color: Theme.of(context).colorScheme.primary, fontSize: 12, fontWeight: FontWeight.bold))), )
By replacing the GetWeekNumberOfYear function in picker_helper.dart with the following code i got it to work correctly: (Note this does not use isHijiri dates since i don't use those)
/// Calculates number of weeks for a given year as per https://en.wikipedia.org/wiki/ISO_week_date#Weeks_per_year
static int numOfWeeks(int year) {
final DateTime dec28 = DateTime(year, 12, 28);
final int dayOfDec28 = int.parse(DateFormat('D').format(dec28));
return ((dayOfDec28 - dec28.weekday + 10) / 7).floor();
}
/// Calculates week number from a date as per https://en.wikipedia.org/wiki/ISO_week_date#Calculation
static int weekNumberr(DateTime date) {
final int dayOfYear = int.parse(DateFormat('D').format(date));
int woy = ((dayOfYear - date.weekday + 10) / 7).floor();
if (woy < 1) {
woy = numOfWeeks(date.year - 1);
} else if (woy > numOfWeeks(date.year)) {
woy = 1;
}
return woy;
}
/// Returns week number for the given date.
static int getWeekNumberOfYear(DateTime date, bool isHijri) {
return weekNumberr(date);
}
Screenshots or Video
Stack Traces
Stack Traces
[Add the Stack Traces here]
On which target platforms have you observed this bug?
Windows, Web
Flutter Doctor output
Doctor output
[Add your output here]