Skip to content

Commit

Permalink
fix: Wrong weekday names when using format-locale in overridden tim…
Browse files Browse the repository at this point in the history
…ezone
  • Loading branch information
basil-gor committed Jun 14, 2024
1 parent fd2efbf commit 5485ca3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/VueDatePicker/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function dayNameIntlMapper(locale: string) {

function dayNameDateFnsMapper(formatLocale: Locale) {
return (day: number) => {
return format(new Date(`2017-01-0${day}T00:00:00+00:00`), 'EEEEEE', { locale: formatLocale });
return format(localToTz(new Date(`2017-01-0${day}T00:00:00+00:00`), 'UTC'), 'EEEEEE', { locale: formatLocale });
};
}

Expand Down
40 changes: 37 additions & 3 deletions tests/unit/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,60 @@ describe('Utils and date utils formatting', () => {
expect(years[1].value).toEqual(2022);
});

it('Should get month values according to locale', () => {
it('Should get long month values according to locale', () => {
const months = getMonths(null, 'en', 'long');

expect(months).toHaveLength(12);
expect(months[0].text).toEqual('January');
expect(months[1].text).toEqual('February');
expect(months[2].text).toEqual('March');
});

it('Should get month values according to formatLocale', () => {
it('Should get short month values according to locale', () => {
const months = getMonths(null, 'en', 'short');

expect(months).toHaveLength(12);
expect(months[0].text).toEqual('Jan');
expect(months[1].text).toEqual('Feb');
expect(months[2].text).toEqual('Mar');
});

it('Should get long month values according to formatLocale', () => {
const months = getMonths(de, 'en', 'long');

expect(months).toHaveLength(12);
expect(months[0].text).toEqual('Januar');
expect(months[1].text).toEqual('Februar');
expect(months[2].text).toEqual('März');
});

it('Should get month values by fallback to locale', () => {
it('Should get long month values by fallback to locale', () => {
// Pass incorrect formatLocale
const months = getMonths(null, 'de', 'long');

expect(months).toHaveLength(12);
expect(months[0].text).toEqual('Januar');
expect(months[1].text).toEqual('Februar');
expect(months[2].text).toEqual('März');
});

it('Should get short month values according to formatLocale', () => {
const months = getMonths(de, 'en', 'short');

expect(months).toHaveLength(12);
expect(months[0].text).toEqual('Jan');
expect(months[1].text).toEqual('Feb');
expect(months[2].text).toEqual('Mär');
});

it('Should get short month values by fallback to locale', () => {
// Pass incorrect formatLocale
const months = getMonths({}, 'de', 'short');

expect(months).toHaveLength(12);
expect(months[0].text).toEqual('Jan');
expect(months[1].text).toEqual('Feb');
expect(months[2].text).toEqual('Mär');
});

it('Should get default pattern', () => {
Expand Down

0 comments on commit 5485ca3

Please sign in to comment.