rough-stuff / wired-elements

Collection of custom elements that appear hand drawn. Great for wireframes or a fun look.
https://wiredjs.com
MIT License
10.5k stars 329 forks source link

Fix (calendar): Fixes display error due to locale first-weekday not Sunday #156 #190

Open elingerojo opened 1 year ago

elingerojo commented 1 year ago

Issue #156

Day number and day names were out of phase when locale first-day-of-the-week was not Sunday. The problem is that the original code assumed Sunday as the first day of the week always.

What has changed:

  1. Accept locale region like: en-GB and de-DE. Previously only the language part was relevant, region was ignored.
  2. Compute first weekday of the week depending on region.
  3. Offset weekday names header and day number to keep phased by columns.

What reviewer should know:

The future and easy way to get the locale first weekday is using Intl.locale.weekInfo.firstDay but is not supported by all major browsers yet, to date. So that, it was obtained by a RegEx string to isolate the locale region and with a extensive region to first weekday map. Understand that this is a hardcoded solution that will cause maintenance debt. To overcome this, both solutions were programmed but the code of the Intl.locale.weekInfo one was commented out for future use.