Skip to content

Commit b8ff0db

Browse files
committedFeb 18, 2024
chore: update branch with master
1 parent b405367 commit b8ff0db

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed
 

‎packages/use-intl/src/core/createFormatter.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,14 @@ export default function createFormatter({
171171
formatOrOptions?: string | DateTimeFormatOptions
172172
) {
173173
return getFormattedValue(
174-
[start, end],
175174
formatOrOptions,
176175
formats?.dateTime,
177176
(options) => {
178177
options = applyGlobalTimeZone(options);
179178

180179
return new Intl.DateTimeFormat(locale, options).formatRange(start, end);
181-
}
180+
},
181+
() => [dateTime(start), dateTime(end)].join(' – ')
182182
);
183183
}
184184

‎packages/use-intl/test/core/createFormatter.test.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,19 @@ describe('dateTimeRange', () => {
286286
)
287287
).toBe('1/10/06, 11:00 AM – 12:00 PM'); // 1 hour more given that the timezone is Europe/Berlin and the date is in UTC
288288
});
289+
it('returns a reasonable fallback if an invalid format is provided', () => {
290+
const formatter = createFormatter({
291+
locale: 'en',
292+
timeZone: 'Europe/Berlin'
293+
});
294+
expect(
295+
formatter.dateTimeRange(
296+
new Date(2007, 0, 10, 10, 0, 0),
297+
new Date(2008, 0, 10, 11, 0, 0),
298+
'unknown'
299+
)
300+
).toBe('1/10/2007 – 1/10/2008');
301+
});
289302
});
290303

291304
describe('list', () => {

0 commit comments

Comments
 (0)