Skip to content
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

startOf('year') not localized #1207

Closed
dodo opened this issue Oct 23, 2013 · 1 comment
Closed

startOf('year') not localized #1207

dodo opened this issue Oct 23, 2013 · 1 comment

Comments

@dodo
Copy link

dodo commented Oct 23, 2013

moment([2016]).startOf('year').week()
// → 1
moment.lang('en-gb') // week.doy = 4
moment([2016]).startOf('year').week()
// → 53

Shouldn't be the second one result in 1 too?
Or it's at least that, what i'm semantically expect from the code.

@icambron
Copy link
Member

That's the expected result. startOf('year') means the start of the calendar year, not the week year, so it's the same in every location (we don't support alternative calendars and en-gb would use a Gregorian calendar anyway). In fact, startOf('year') is redundant here because moment([2016]) already returns Jan 1.

You may know this, but what doy does is change how the weeks are numbered, because the week year doesn't start at the same time as the calendar year. The way it works is that week 1 is the week that includes the first instance of doy that's in the new calendar year. Jan 1, 2016 is a Friday, so in the US (doy = 6 = Saturday), we look for the first Saturday in the calendar year (Jan 2), and call the week that includes it week 1. So that's the week starting on the previous Sunday (because dow=0), which is Dec 27. Thus Jan 1 is in week 1. In the UK, doy = 4, so we look for the first Thursday of the calendar year (which is Jan 7), and call that the first week. So week 1 starts on Jan 4, because dow=1. Thus Jan 1 is in the final week of the previous week year.

It sounds like you may be looking for something like moment([2016]).startOf('week-year'), which doesn't exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants