Skip to content

Commit

Permalink
feat: Add luxon configuration with locale weeks set to true
Browse files Browse the repository at this point in the history
Add configuration option for luxon with `useLocaleWeeks` for better flexebility.\nThe new configuration is exported seperetly in order to make an additional option and not cause breaking changes.
  • Loading branch information
ShtibsDev committed Feb 20, 2024
1 parent 1f725d0 commit c9c55fd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/generate/luxon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const normalizeFormat = (format: string): string =>
*/
const normalizeLocale = (locale: string): string => locale.replace(/_/g, '-');

const generateConfig: GenerateConfig<DateTime> = {
const getGenerateConfig = (useLocaleWeeks?: boolean): GenerateConfig<DateTime> => ({
// get
getNow: () => DateTime.local(),
getFixedDate: (string) => DateTime.fromFormat(string, 'yyyy-MM-dd'),
Expand Down Expand Up @@ -85,9 +85,11 @@ const generateConfig: GenerateConfig<DateTime> = {
isValidate: (date) => date.isValid,

locale: {
getWeekFirstDate: (locale, date) => date.setLocale(normalizeLocale(locale)).startOf('week'),
getWeekFirstDate: (locale, date) =>
date.setLocale(normalizeLocale(locale)).startOf('week', { useLocaleWeeks }),
getWeekFirstDay: (locale) =>
DateTime.local().setLocale(normalizeLocale(locale)).startOf('week').weekday,
DateTime.local().setLocale(normalizeLocale(locale)).startOf('week', { useLocaleWeeks })
.weekday,
getWeek: (locale, date) => date.setLocale(normalizeLocale(locale)).weekNumber,
getShortWeekDays: (locale) => {
const weekdays = Info.weekdays(weekDayFormatMap[locale] || 'short', {
Expand Down Expand Up @@ -126,6 +128,8 @@ const generateConfig: GenerateConfig<DateTime> = {
return null;
},
},
};
});

const generateConfig = getGenerateConfig();
export const generateConfigWithLocale = getGenerateConfig(true);
export default generateConfig;

0 comments on commit c9c55fd

Please sign in to comment.