-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Feature request: weekNumber #44
Comments
Glad you enjoy it! By week number do you mean the week of the year? So Jan 1 being 1, Jan 10 be 2? |
Exactly! I tried to see if I could create something but it looks more challenging then I expected. function weekNumber(givenDate: Date, startOfWeek: number) {
const millisecondsInWeek = 604800000;
const startDate = weekStart(givenDate, startOfWeek);
const startOfYear = yearStart(startDate);
const diff = startDate.getTime() - startOfYear.getTime();
return Math.round(diff / millisecondsInWeek) + 1;
} But this still fails for dates which |
@DJWassink I think you actually have it about right except for |
Ooh wow yeah 🤦♂️ However the bug still persist for other dates where the start of week is in the previous year. I simply test with a big loop that goes through every day starting in 2013 till now and compare the moment.js week versus mine. |
Hmmm... wait — how could 2013-12-31 be in week 1? Are we saying that week one of 2024 was (assuming sunday is the first day of week) would be Dec 31 - Sat 6th even though it spans the year gap? Or is week one the 7th - 13th I guess there is some subjectivity and intuition there that would need to be nailed down. |
As far as I'm familiar with calendars the first week of 2024 would be Dec 31 - 6th of jan (on a sunday calendar). |
Yeah, I suppose I haven’t thought much about it honestly I guess that does make sense. I wouldn’t wake up on the 7th of January and think to myself, "ok lets get this first week of the year underway". Ok! I think we could get this into tempo for sure. |
Also I think this must be relative to |
Thanks for this library its a delight to use!
One feature I am missing is for a way to get the week number of a given date + startOfWeekDay.
Would be cool if this could also be included in the formatting tokens.
The text was updated successfully, but these errors were encountered: