werner-scholtz / kalender

An elegantly crafted Flutter calendar UI package.
MIT License
107 stars 29 forks source link

issue with setting the firstDayOfWeek to Sunday on Week view #55

Closed Shui-Be closed 7 months ago

Shui-Be commented 7 months ago

Hi!

there's an issue when the firstDayOfWeek is set to DateTime.sunday but the calendar header is showing the next week's range.

in the picture below, the time range for week 17 is showing (Sun 28 - Sat 4), where it is supposed to be (Sun 21 - Sat -27), Time zone in Toronto, ON (GMT-4) image

Steps to reproduce:

  1. clone the app and run web_demo project
  2. create a class that extends the WeekConfiguration default the firstDayOfWeek to DateTime.sunday, (this class is basically a copy of the WeekConfiguration but adding the firstDayOfWeek option, this is needed because I couldn't find any default configuration that exposes the firstDayOfWeek property): image
  3. run the app and see that the date range in calendar header is showing the next weeks ranges, the correct date ranges should be Sunday April 21st 2024 - Saturday April 27th 2024 (however, the week number 17 shown in the top left does seem to be correct)
werner-scholtz commented 7 months ago

Hi Thanks will take a look at this.

werner-scholtz commented 7 months ago

Need to update the week configuration to include the super.firstDayOfWeek :+1:

werner-scholtz commented 7 months ago

Taking a look at https://en.wikipedia.org/wiki/ISO_week_date monday seems to be the start of new weeks: What I will do is use the Monday that is displayed to calculate the week-number if Saturday / Sunday / Monday is used for firstDayOfWeek. However if some other date is selected like Tuesday / Wednesday/ Thursday / Friday then I will display both week-numbers ex "17-18"

kayatmin commented 7 months ago

@werner-scholtz sry for tagging directly, thanks for the quick update.

when i switched the First day of week dropdown in the demo app from Monday to Sunday, the week number and week range seems to be displaying the next week's number and range.

a picture is worth a thousand words.. : image

image

in the pictures above: my current day is April 23rd, 2024, the week range is displaying from April 28 to May 4th instead of April 21 to April 27.

werner-scholtz commented 7 months ago

@kayatmin, just checking the issue is that it jumps to the next week instead of displaying the current week ? Everything else is fine ?

kayatmin commented 7 months ago

@werner-scholtz yes that's correct, everything else seems to be working well, i.e., clicking on the arrow to go previous and next weeks displays the ranges correctly, callbacks returns the correct date also.

werner-scholtz commented 7 months ago

Okay good to know, the issue is most likely related to how this is calculated.

Edit: further investigation seems like calculating the adjustedDateTimeRange shifts the visibleDateTimeRanges of each index this