Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker.test throws error after deleting a defaultValue in DT/ST when current timeZone is ST/DT #7399

Closed
majornista opened this issue Nov 19, 2024 · 0 comments · Fixed by #7401
Labels
bug Something isn't working rsp:DatePicker

Comments

@majornista
Copy link
Collaborator

Provide a general summary of the issue here

The following test fails when the defaultValue timeZone's daylight savings/standard time does not match the current timeZone's standard/daylight savings time.

it('should keep timeZone from defaultValue when date and time are cleared', async function () {
let {getAllByRole} = render(
<DatePicker
label="Date"
defaultValue={parseZonedDateTime(
'2024-09-21T00:00:00[America/Los_Angeles]'
)} />
);
let combobox = getAllByRole('group')[0];
expectPlaceholder(combobox, '9/21/2024, 12:00 AM PDT');
await user.tab();
await user.keyboard('{Backspace}');
await user.tab();
let i;
for (i = 0; i < 2; i++) {
await user.keyboard('{Backspace}');
}
await user.tab();
for (i = 0; i < 4; i++) {
await user.keyboard('{Backspace}');
}
await user.tab();
for (i = 0; i < 2; i++) {
await user.keyboard('{Backspace}');
}
await user.tab();
for (i = 0; i < 2; i++) {
await user.keyboard('{Backspace}');
}
await user.tab();
await user.keyboard('{Backspace}');
expectPlaceholder(combobox, 'mm/dd/yyyy, ––:–– AM PDT');
});

🤔 Expected Behavior?

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.

😯 Current Behavior

The test is written to always expect "PDT" Pacific Daylight Savings Time, which means it will fail when we're on standard time.

expectPlaceholder(combobox, 'mm/dd/yyyy, ––:–– AM PDT');

💁 Possible Solution

Use the timeZoneName for the current date time.

      let timeZoneName =
        new DateFormatter('en-US',
          {
            timeZone: 'America/Los_Angeles',
            timeZoneName: 'short'
          })
          .formatToParts(new Date())
          .find(p => p.type === 'timeZoneName')
          .value;

      expectPlaceholder(combobox, `mm/dd/yyyy, ––:–– AM ${timeZoneName}`);

🔦 Context

No response

🖥️ Steps to Reproduce

Run yarn test packages/@react-spectrum/datepicker/test/DatePicker.test.js from the first Sunday in November to the second Sunday in March.

Version

@react-spectrum/datepicker@3.10.3

What browsers are you seeing the problem on?

Firefox, Chrome, Safari, Microsoft Edge

If other, please specify.

No response

What operating system are you using?

MacOS

🧢 Your Company/Team

Adobe/Accessibility

🕷 Tracking Issue

No response

@majornista majornista added bug Something isn't working rsp:DatePicker labels Nov 19, 2024
majornista added a commit that referenced this issue Nov 19, 2024
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.
majornista added a commit that referenced this issue Nov 19, 2024
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.
majornista added a commit that referenced this issue Nov 20, 2024
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.
github-merge-queue bot pushed a commit that referenced this issue Nov 20, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rsp:DatePicker
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant