UNPKG

date-picker-svelte

Version:
66 lines (65 loc) 1.91 kB
export function getLocaleDefaults() { return { weekdays: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], months: [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', ], shortMonths: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', ], weekStartsOn: 1, }; } export function getInnerLocale(locale) { const innerLocale = getLocaleDefaults(); if (typeof locale.weekStartsOn === 'number') { innerLocale.weekStartsOn = locale.weekStartsOn; } if (locale.months) innerLocale.months = locale.months; if (locale.shortMonths) innerLocale.shortMonths = locale.shortMonths; if (locale.weekdays) innerLocale.weekdays = locale.weekdays; return innerLocale; } /** Create a Locale from a date-fns locale */ export function localeFromDateFnsLocale(dateFnsLocale) { const locale = getLocaleDefaults(); if (typeof dateFnsLocale.options?.weekStartsOn === 'number') { locale.weekStartsOn = dateFnsLocale.options.weekStartsOn; } if (dateFnsLocale.localize) { for (let i = 0; i < 7; i++) { // widths: narrow, short, abbreviated, wide, any locale.weekdays[i] = dateFnsLocale.localize.day(i, { width: 'short' }); } for (let i = 0; i < 12; i++) { locale.months[i] = dateFnsLocale.localize.month(i, { width: 'wide' }); locale.shortMonths[i] = dateFnsLocale.localize.month(i, { width: 'abbreviated' }); } } return locale; }