dayjs
dayjs copied to clipboard
.weekYear() unexpectedly returns year (and not week)
Describe the bug The weekYear() method is supposed to return the week of the year but instead it returns the year itself.
Expected behavior When calling this method the following way: dayjs("2021-01-01").weekYear() it returns 2021, when the expected result would be the week of the year that day corresponds to, never the year
Information
- Day.js: ^1.10.3,
- Browser: Chrome 88.0.4324.150
- Time zone: UTC
This api will let you to get the week-year according to the locale.
Because the first day of the first week does not always fall on the first day of the year, sometimes the week-year will differ from the month year.
I understand the purpose of the API and it is exactly what I am looking for. However it returns the year (2021) not the week (either 53 or 1). I am interested in the week number and as far as I know this API should return the week number. However it returns the year number, not the week.
@seryi27 I guess that you are looking for week()
// What week is it this date?
dayjs.extend(weekOfYear)
dayjs('2018-06-27').week()
// 26
dayjs('2018-01-01').week()
// 1
dayjs('2017-12-31').week()
// 1
// What week-year is it this date?
dayjs.extend(weekYear)
dayjs.extend(weekOfYear)
dayjs('2018-06-27').weekYear()
// 2018
dayjs('2018-01-01').weekYear()
// 2018
dayjs('2017-12-31').weekYear()
// 2018
Maybe the issue the documentation then?
It says
WeekYear adds .weekYear() API to get locale aware week of the year.
https://day.js.org/docs/en/plugin/week-year
¿Quizás entonces el problema es la documentación?
Dice
WeekYear agrega la API .weekYear() para conocer la semana del año en función de la configuración regional.
https://day.js.org/docs/en/plugin/week-year
+1