Skip to content

Instantly share code, notes, and snippets.

@ralekna
Created October 23, 2023 10:29
Show Gist options
  • Save ralekna/7440e5e7a04ffbf1fe66b56a2e1ded1d to your computer and use it in GitHub Desktop.
Save ralekna/7440e5e7a04ffbf1fe66b56a2e1ded1d to your computer and use it in GitHub Desktop.
Intl.Locale.prototype.getWeekInfo().firstDay replacement function
const LOCALES_TO_START_OF_WEEK = {
'af-ZA': 7,
'am-ET': 7,
'ar-AE': 1,
'ar-BH': 6,
'ar-DZ': 1,
'ar-EG': 6,
'ar-IQ': 6,
'ar-JO': 7,
'ar-KW': 6,
'ar-LB': 1,
'ar-LY': 6,
'ar-MA': 1,
'arn-CL': 1,
'ar-OM': 6,
'ar-QA': 6,
'ar-SA': 7,
'ar-SD': 6,
'ar-SY': 6,
'ar-TN': 1,
'ar-YE': 7,
'as-IN': 7,
'az-az': 1,
'az-Cyrl-AZ': 1,
'az-Latn-AZ': 1,
'ba-RU': 1,
'be-BY': 1,
'bg-BG': 1,
'bn-BD': 7,
'bn-IN': 7,
'bo-CN': 7,
'br-FR': 1,
'bs-Cyrl-BA': 1,
'bs-Latn-BA': 1,
'ca-ES': 1,
'co-FR': 1,
'cs-CZ': 1,
'cy-GB': 1,
'da-DK': 1,
'de-AT': 1,
'de-CH': 1,
'de-DE': 1,
'de-LI': 1,
'de-LU': 1,
'dsb-DE': 1,
'dv-MV': 5,
'el-CY': 1,
'el-GR': 1,
'en-029': 1,
'en-AU': 1,
'en-BZ': 7,
'en-CA': 7,
'en-cb': 1,
'en-GB': 1,
'en-IE': 1,
'en-IN': 7,
'en-JM': 7,
'en-MT': 7,
'en-MY': 1,
'en-NZ': 1,
'en-PH': 7,
'en-SG': 7,
'en-TT': 7,
'en-US': 7,
'en-ZA': 7,
'en-ZW': 7,
'es-AR': 1,
'es-BO': 1,
'es-CL': 1,
'es-CO': 7,
'es-CR': 1,
'es-DO': 7,
'es-EC': 1,
'es-ES': 1,
'es-GT': 7,
'es-HN': 7,
'es-MX': 7,
'es-NI': 7,
'es-PA': 7,
'es-PE': 7,
'es-PR': 7,
'es-PY': 7,
'es-SV': 7,
'es-US': 7,
'es-UY': 1,
'es-VE': 7,
'et-EE': 1,
'eu-ES': 1,
'fa-IR': 6,
'fi-FI': 1,
'fil-PH': 7,
'fo-FO': 1,
'fr-BE': 1,
'fr-CA': 7,
'fr-CH': 1,
'fr-FR': 1,
'fr-LU': 1,
'fr-MC': 1,
'fy-NL': 1,
'ga-IE': 1,
'gd-GB': 1,
'gd-ie': 1,
'gl-ES': 1,
'gsw-FR': 1,
'gu-IN': 7,
'ha-Latn-NG': 1,
'he-IL': 7,
'hi-IN': 7,
'hr-BA': 1,
'hr-HR': 1,
'hsb-DE': 1,
'hu-HU': 1,
'hy-AM': 1,
'id-ID': 7,
'ig-NG': 1,
'ii-CN': 7,
'in-ID': 7,
'is-IS': 1,
'it-CH': 1,
'it-IT': 1,
'iu-Cans-CA': 7,
'iu-Latn-CA': 7,
'iw-IL': 7,
'ja-JP': 7,
'ka-GE': 1,
'kk-KZ': 1,
'kl-GL': 1,
'km-KH': 7,
'kn-IN': 7,
'kok-IN': 7,
'ko-KR': 7,
'ky-KG': 1,
'lb-LU': 1,
'lo-LA': 7,
'lt-LT': 1,
'lv-LV': 1,
'mi-NZ': 1,
'mk-MK': 1,
'ml-IN': 7,
'mn-MN': 1,
'mn-Mong-CN': 7,
'moh-CA': 7,
'mr-IN': 7,
'ms-BN': 1,
'ms-MY': 1,
'mt-MT': 7,
'nb-NO': 1,
'ne-NP': 7,
'nl-BE': 1,
'nl-NL': 1,
'nn-NO': 1,
'no-no': 1,
'nso-ZA': 7,
'oc-FR': 1,
'or-IN': 7,
'pa-IN': 7,
'pl-PL': 1,
'prs-AF': 6,
'ps-AF': 6,
'pt-BR': 7,
'pt-PT': 7,
'qut-GT': 7,
'quz-BO': 1,
'quz-EC': 1,
'quz-PE': 7,
'rm-CH': 1,
'ro-mo': 7,
'ro-RO': 1,
'ru-mo': 7,
'ru-RU': 1,
'rw-RW': 1,
'sah-RU': 1,
'sa-IN': 7,
'se-FI': 1,
'se-NO': 1,
'se-SE': 1,
'si-LK': 1,
'sk-SK': 1,
'sl-SI': 1,
'sma-NO': 1,
'sma-SE': 1,
'smj-NO': 1,
'smj-SE': 1,
'smn-FI': 1,
'sms-FI': 1,
'sq-AL': 1,
'sr-BA': 1,
'sr-CS': 1,
'sr-Cyrl-BA': 1,
'sr-Cyrl-CS': 1,
'sr-Cyrl-ME': 1,
'sr-Cyrl-RS': 1,
'sr-Latn-BA': 1,
'sr-Latn-CS': 1,
'sr-Latn-ME': 1,
'sr-Latn-RS': 1,
'sr-ME': 1,
'sr-RS': 1,
'sr-sp': 1,
'sv-FI': 1,
'sv-SE': 1,
'sw-KE': 7,
'syr-SY': 6,
'ta-IN': 7,
'te-IN': 7,
'tg-Cyrl-TJ': 1,
'th-TH': 7,
'tk-TM': 1,
'tlh-QS': 1,
'tn-ZA': 7,
'tr-TR': 1,
'tt-RU': 1,
'tzm-Latn-DZ': 1,
'ug-CN': 7,
'uk-UA': 1,
'ur-PK': 7,
'uz-Cyrl-UZ': 1,
'uz-Latn-UZ': 1,
'uz-uz': 1,
'vi-VN': 1,
'wo-SN': 1,
'xh-ZA': 7,
'yo-NG': 1,
'zh-CN': 7,
'zh-HK': 7,
'zh-MO': 7,
'zh-SG': 7,
'zh-TW': 7,
'zu-ZA': 7,
}
/**
* Returns the start of the week for the given locale
* We need this implementation because currently Intl.Locale.prototype.getWeekInfo() is supported only in Safari (2023-10-23)
* @param {string} locale locale ID
* @returns {number} 1 for Monday, 7 for Sunday.
*/
export const getStartOfWeekByLocale = (locale: string): number => LOCALES_TO_START_OF_WEEK[locale] || 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment