Skip to content

Commit 9170093

Browse files
author
Michael Jordan
authored
fix(#7399): DatePicker.test fails with daylight savings change (#7401)
If the defaultValue is on daylight savings time and the user clears the value while in a time zone on standard time, the DatePicker's time zone will change to standard time. I think this is the correct behavior, however, the test is written to always expect "PDT" Pacific Daylight Savings Time, which means it will fail when we're on standard time.
1 parent 52bf91b commit 9170093

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/@react-spectrum/datepicker/test/DatePicker.test.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import {act, fireEvent, pointerMap, render as render_, waitFor, within} from '@react-spectrum/test-utils-internal';
1414
import {Button} from '@react-spectrum/button';
15-
import {CalendarDate, CalendarDateTime, EthiopicCalendar, getLocalTimeZone, JapaneseCalendar, parseZonedDateTime, toCalendarDateTime, today} from '@internationalized/date';
15+
import {CalendarDate, CalendarDateTime, DateFormatter, EthiopicCalendar, getLocalTimeZone, JapaneseCalendar, parseZonedDateTime, toCalendarDateTime, today} from '@internationalized/date';
1616
import {DatePicker} from '../';
1717
import {Form} from '@react-spectrum/form';
1818
import {Provider} from '@react-spectrum/provider';
@@ -584,7 +584,7 @@ describe('DatePicker', function () {
584584
let month = parts.find(p => p.type === 'month').value;
585585
let day = parts.find(p => p.type === 'day').value;
586586
let year = parts.find(p => p.type === 'year').value;
587-
587+
588588
expectPlaceholder(combobox, `${month}/${day}/${year}, 12:00 AM`);
589589

590590
await user.keyboard('{ArrowRight}');
@@ -1928,7 +1928,17 @@ describe('DatePicker', function () {
19281928
await user.tab();
19291929
await user.keyboard('{Backspace}');
19301930

1931-
expectPlaceholder(combobox, 'mm/dd/yyyy, ––:–– AM PDT');
1931+
let timeZoneName =
1932+
new DateFormatter('en-US',
1933+
{
1934+
timeZone: 'America/Los_Angeles',
1935+
timeZoneName: 'short'
1936+
})
1937+
.formatToParts(new Date())
1938+
.find(p => p.type === 'timeZoneName')
1939+
.value;
1940+
1941+
expectPlaceholder(combobox, `mm/dd/yyyy, ––:–– AM ${timeZoneName}`);
19321942
});
19331943

19341944
it('should keep timeZone from defaultValue when date and time are cleared then set', async function () {

0 commit comments

Comments
 (0)