Last active
February 6, 2020 10:22
-
-
Save jagomf/07729b4a341ad74b596cd0a9da694e29 to your computer and use it in GitHub Desktop.
Generate constants with months/weekdays names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// More info on locales and codes for names on MDN 'toLocaleString' | |
weekdaysArray(locale = 'en-us', startMonday = false) { | |
const initYear = 2006; // Year that started on the first day of week | |
return Array.from({ length: 7 }, (v, k) => k) | |
.map(weekday => new Date(initYear, 0, weekday + (startMonday ? 1 : 0) + 1) | |
.toLocaleString(locale, { weekday: 'narrow' })); | |
} | |
monthsArray(locale = 'en-us') { | |
return Array.from({ length: 12 }, (v, k) => k) | |
.map(month => new Date(2000, month, 1) | |
.toLocaleString(locale, { month: 'long' })); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment