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

weekYear(Number) jumps to the previous day of the week (and wraps around) #3944

Closed
xehpuk opened this issue May 2, 2017 · 4 comments · Fixed by #6193
Closed

weekYear(Number) jumps to the previous day of the week (and wraps around) #3944

xehpuk opened this issue May 2, 2017 · 4 comments · Fixed by #6193
Labels

Comments

@xehpuk
Copy link

xehpuk commented May 2, 2017

Description of the Issue and Steps to Reproduce:

For the German locale, weekYear(Number) does not preserve the day of the week, even if Number === weekYear(). It always jumps to the previous day and wraps around on Sunday.

import moment from 'moment'

moment.locale('de')

const date = moment('2016-01-01')

date.weekYear(2015) // 2015-12-31 Th
date.weekYear(2015) // 2015-12-30 We
date.weekYear(2015) // 2015-12-29 Tu
date.weekYear(2015) // 2015-12-28 Mo
date.weekYear(2015) // 2016-01-03 Su
date.weekYear(2015) // 2016-01-02 Sa
date.weekYear(2015) // 2016-01-01 Fr

// Workaround:
const day = date.day() // 5
date.weekYear(2015).day(day) // 2016-01-01 Fr

https://jsfiddle.net/mtvsr738/

Environment:

Chrome 57, Firefox 52 and Edge 38 on Windows 10

Other information that may be helpful:

Tue May 02 2017 21:08:56 GMT+0200 (Mitteleuropäische Sommerzeit)
2.5.2017, 21:08:56
-120
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
2.18.1
@icambron
Copy link
Member

icambron commented May 3, 2017

Looks like a bug to me. Should give the same week number and weekday. Would accept a patch.

@icambron icambron added the Bug label May 3, 2017
@MTelling
Copy link

MTelling commented May 4, 2017

Seems to be an issue in other locales as well. I can repro in 'ca' and 'da' as well locally.

@xehpuk
Copy link
Author

xehpuk commented May 5, 2017

dayOfYearFromWeeks(year, week, weekday, dow, doy) seems to calculate a wrong dayOfYear.

moment([2015, 11, 27]).locale('de').weekYear(2015) leads to the call dayOfYearFromWeeks(2015, 52, 6, 1, 4) which then calculates dayOfYear = 360, while it should be 361.

nikofil added a commit to nikofil/moment that referenced this issue Oct 18, 2018
Fixes the setting of the wrong weekday under some locales when setting
the weekday due to converting it to the local weekday twice.

Fixes moment#3944

Signed-off-by: Nikos Filippakis <aesmade@gmail.com>
nikofil added a commit to nikofil/moment that referenced this issue Jan 21, 2019
Fixes the setting of the wrong weekday under some locales when setting
the weekday due to converting it to the local weekday twice.

Fixes moment#3944

Signed-off-by: Nikos Filippakis <aesmade@gmail.com>
Signed-off-by: Nikos Filippakis <nikolaos.filippakis@cern.ch>
@Nosfistis
Copy link

I am having the same issue, it behaves as if doy is ignored. @nikofil are you preparing a PR?

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