javascriptdatemomentjs

Is there a way to count number of ISO weeks in a given year using Moment.js?


I need to determine how many ISO weeks a year has.

My attempt looks like this

moment.tz(2019, "YYYY", "UTC").endOf("year").isoWeek()

But that doesn't do the job. 31st of December is ISO week 1 in some cases.

Ofc, there are probably some ugly ways to get the result, but i would like a clean code.


Solution

  • It doesn't seem like moment.js provides an interface for this.

    This seems to be the solution (pure JS) Get weeks in year