Skip to content

Commit

Permalink
Merge pull request #911 from basil-gor/fix-weekday-names-tz
Browse files Browse the repository at this point in the history
fix: Wrong weekday names when using `format-locale` in overridden timezone
  • Loading branch information
Jasenkoo authored Jun 20, 2024
2 parents 10fbfed + 905585c commit e797f8b
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', () => {
// @ts-expect-error 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 e797f8b

Please sign in to comment.