0

https://en.wikipedia.org/wiki/Workweek_and_weekend (a table on this page have Weekdays per country).

Is there a way to get the weekend days per culture code in Typescript/Javascript? Most are Sat-Sun, but there are some exceptions.. i.e. Mexico = only Sunday, some middle-eastern countries = Fri-Sat, and etc. I would like to get Start and End day of the weekend per culture, if possible. moment.js doesn't seem to have this functionality (and there's a business-days library based on moment, but that one seems to be Sat-Sun friendly).

007
  • 2,136
  • 4
  • 26
  • 46
  • Unfortunately no, It's returning Sat-Sun for Mexico. Haven't checked all other. – 007 Jul 25 '23 at 20:39
  • Intl *is* the proper way to do this. If you disagree with some of the returned values for whatever reason, file a bug report on the API, or add your own special cases. But in general, it will return the correct values. – Bergi Jul 25 '23 at 23:58

1 Answers1

0

Intl.DateTimeFormat

The Intl.DateTimeFormat object enables language-sensitive date and time formatting.

In particular see .getWeekInfo()

The getWeekInfo() method of Intl.Locale instances returns a weekInfo object with the properties firstDay, weekend and minimalDays for this locale.

Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91
  • It seems to return Sat-Sun for Mexico, when it should be just Sun. :( – 007 Jul 25 '23 at 21:14
  • You can roll your own script using `formatToParts` – Ronnie Royston Jul 25 '23 at 21:15
  • Not sure I follow. Different locale can have different weekend days and that too can change. Are you suggesting a custom mapping or something else? If custom mapping, that would be the last approach. I was hoping to find a prebuilt/built-in solution, if possible. If not, can you please elaborate? – 007 Jul 25 '23 at 21:33