dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

.weekYear() unexpectedly returns year (and not week)

Open seryi27 opened this issue 4 years ago • 5 comments
trafficstars

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

seryi27 avatar Feb 22 '21 15:02 seryi27

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.

iamkun avatar Feb 23 '21 02:02 iamkun

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 avatar Feb 23 '21 10:02 seryi27

@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

marcusasplund avatar Mar 12 '21 13:03 marcusasplund

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

alexkuc avatar Jun 12 '22 18:06 alexkuc

¿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

vallemar avatar Jan 12 '24 07:01 vallemar