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.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: align days and week days on calendar #31641
fix: align days and week days on calendar #31641
Changes from 9 commits
72fc564
3dd8f85
a13abd6
5b6b2ff
aa015de
d4a2c58
a355972
f9d8b86
82bc4d7
026ee86
5fb6e98
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for this change? push vs unshift
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unshift will add the empty days at the beginning of the calendar. The way it was done before (see snippet below), it would FIRST add the empty spaces (push) but now we add all the days first and only then we add the empty spaces at the beginning (unshift)
this no longer works because now our week starts on 1 and ends on 0 (and it could change). This breaks as the start is higher than the end (1,2,3,4,5,6,0).
hope this makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am on mobile so I missed on thing. The snippet I pasted above (old code) would go from 0 (start of the week assumed earlier - which is now wrong) until the first week day of the month (which before would always be 0 or higher). Now, because week starts on 1 (Sunday) the first week day of a month could be Sunday (0) and the loop would break and cause infinite loop. My change (unshift) accounts for any start of the week and any first week day of the month.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also be renamed to getWeekStartDay and similar for end function below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MonilBhavsar the idea was to follow the same naming convention used
date-fns
which is the underlying library we use:https://github.com/date-fns/date-fns/blob/a39b8058f777517e8040193ba597dff18765951a/src/types.ts#L192-L195
This allows us to do things like this:
instead of:
IMO more readable and consistent to keep it as is (
WEEK_STARTS_ON
,getWeekStartsOn
andgetWeekEndsOn
).Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense 👍
let's keep it that way. thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start day is always constant, so this is not required now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, it's not required, but the idea was to allow for flexibility. If we ever decide to switch to Sunday (which is the standard in the US, where most of our customers are), we won't have to remember to change it here as well (or have two constants). Also, there seem to be an appetite to make the start of the week dynamic at some point based on locale, so this function will be ready for it when/if that day comes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a matrix for some month of year 2025, may be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MonilBhavsar added a few more tests including a month that starts on Monday, one that starts on Sunday, February (less days) and one more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!