Configurable start of the week
Closed this issue · 7 comments
Hi,
I live in the UK and have been using this library to calculate events.
Here in the UK we use the start of the week as Monday. However, I have noticed in your library that for some event date calculations you are using Sunday. This does not match Outlook (when used in the UK with default configuration) recurrence calculations.
Would it be possible to make the start day of the week configurable?
e.g. this is one example of where the start day of the week needs to be configurable.
Sure. I will work on this, Mark @Defstun . I will try to squeeze this in during this week,,, Thanks.
How about just using CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek? This way we do not need to add settings, @Defstun ?
On second thought explicit setting is better for backwards compatibility. I will just add a comment for folks how to set it and bump the version to 2.0
Hi Sergey, thanks for responding and agreeing to do the work. 👍
The setting idea sounds much better as long as it can be changed at runtime. Perhaps through the construction of the class Calculator?
I can make the changes and send you a PR if that would help.
Sure!. I do not say no to help, Mark :-).
I've added a PR for it. I've added some tests that hopefully explains the issue we were having.
The logic of "If the first occurrence lands in the current week (indicated by the start date) then use it, if it does not then use the next interval date." was causing us issues when the first day of the week was Sunday. When having a weekly event on a Sunday with an interval > 1, it always chose the next interval, not the next occurrence of Sunday in the calendar.
With a configurable first day of the week, we can set this to Monday and it will choose the next occurrence of Sunday in the calculation, rather than the next interval.
Hope that all makes sense.
If the PR is not what you intended for a solution, obviously feel free to reject it but hopefully it's helped communicate the problem so you can add your own solution.
Again, thanks for responding to my issue. 👍
Great, thanks.