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
Wrong week number is returned from the "week()" function #4710
Comments
We encounter the same problem. |
@numen31337 You probably want to be using weekYear() instead of @Blapi |
I'll clarify this a bit, here is code with dates and related output: const a = moment([2018, 11, 29]);
console.log(
`a year: ${a.year()}`, //a year: 2018
`a month: ${a.month()}`, //a month: 11
`a date: ${a.date()}`, //a date: 29
`a week: ${a.week()}`, //a week: 52
`a weekYear: ${a.weekYear()}`, //a weekYear: 2018
);
const b = moment([2018, 11, 30]);
console.log(
`b year: ${b.year()}`, //b year: 2018
`b month: ${b.month()}`, //b month: 11
`b date: ${b.date()}`, //b date: 30
`b week: ${b.week()}`, //b week: 1 <=== Why 1?
`b weekYear: ${b.weekYear()}`, //b weekYear: 2019 <=== Why 2019?
); The issue for me is that const fromDateStartWeek = fromDate.startOf('week');
const toDateStartWeek = toDate.startOf('week');
return toDateStartWeek.diff(fromDateStartWeek, 'weeks'); But I still wundering about this |
I think you probably have an expectation of how week-numbering works that differs from established practice. e.g. you think 1st January is always in week 1, and 31st December is always in week 52/53 - and, to be fair, some wall calendars do show week numbering like that. When it comes to standardising week numbers, the preference is to ensure that a week always contains 7 days. For the ISO standard: weeks runs from Monday-Sunday, and week 1 contains the first Thursday of the year. Which means Monday-Wednesday of week 1 may fall in the previous year. (this'll happen in 2019/2020: December 29th-31st of 2019 are considered as part of Week 1 of 2020) You're not using the ISO methods ( December 30th 2018 is a Sunday, and the first day of a week in your locale. Only 2 days of that week fall in 2018, the rest of it is in 2019. The rules for your locale are used to decide whether that week (all 7 days) are classed as 2018 week 53, or 2019 week 1. In your case, they've said 2019 week 1. |
Thank you for the clarification. That's really surprising for me. I really miss the API like from Apple Calendar dateComponents(_:from:to:) where you can ask for a diff in specific components, in my case |
Description of the Issue and Steps to Reproduce:
When creating a date, for example
[2018, 11, 29]
, and performing theweek
function the result is52
, but for[2018, 11, 30]
and for31
as well it returns1
. The expected result is52
.Example
jsbin live example
Environment:
Safari 11.1.2 on OSX
Other information that may be helpful:
The text was updated successfully, but these errors were encountered: