Skip to content

Commit e797f8b

Browse files
authored
Merge pull request #911 from basil-gor/fix-weekday-names-tz
fix: Wrong weekday names when using `format-locale` in overridden timezone
2 parents 10fbfed + 905585c commit e797f8b

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/VueDatePicker/utils/util.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function dayNameIntlMapper(locale: string) {
3535

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

tests/unit/utils.spec.ts

+37-3
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,60 @@ describe('Utils and date utils formatting', () => {
122122
expect(years[1].value).toEqual(2022);
123123
});
124124

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

128128
expect(months).toHaveLength(12);
129129
expect(months[0].text).toEqual('January');
130+
expect(months[1].text).toEqual('February');
131+
expect(months[2].text).toEqual('March');
130132
});
131133

132-
it('Should get month values according to formatLocale', () => {
134+
it('Should get short month values according to locale', () => {
135+
const months = getMonths(null, 'en', 'short');
136+
137+
expect(months).toHaveLength(12);
138+
expect(months[0].text).toEqual('Jan');
139+
expect(months[1].text).toEqual('Feb');
140+
expect(months[2].text).toEqual('Mar');
141+
});
142+
143+
it('Should get long month values according to formatLocale', () => {
133144
const months = getMonths(de, 'en', 'long');
134145

135146
expect(months).toHaveLength(12);
136147
expect(months[0].text).toEqual('Januar');
148+
expect(months[1].text).toEqual('Februar');
149+
expect(months[2].text).toEqual('März');
137150
});
138151

139-
it('Should get month values by fallback to locale', () => {
152+
it('Should get long month values by fallback to locale', () => {
140153
// Pass incorrect formatLocale
141154
const months = getMonths(null, 'de', 'long');
142155

143156
expect(months).toHaveLength(12);
144157
expect(months[0].text).toEqual('Januar');
158+
expect(months[1].text).toEqual('Februar');
159+
expect(months[2].text).toEqual('März');
160+
});
161+
162+
it('Should get short month values according to formatLocale', () => {
163+
const months = getMonths(de, 'en', 'short');
164+
165+
expect(months).toHaveLength(12);
166+
expect(months[0].text).toEqual('Jan');
167+
expect(months[1].text).toEqual('Feb');
168+
expect(months[2].text).toEqual('Mär');
169+
});
170+
171+
it('Should get short month values by fallback to locale', () => {
172+
// @ts-expect-error Pass incorrect formatLocale
173+
const months = getMonths({}, 'de', 'short');
174+
175+
expect(months).toHaveLength(12);
176+
expect(months[0].text).toEqual('Jan');
177+
expect(months[1].text).toEqual('Feb');
178+
expect(months[2].text).toEqual('Mär');
145179
});
146180

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

0 commit comments

Comments
 (0)