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

[pickers] Update pickers when new value has a distinct timezone #7853

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions packages/x-date-pickers/src/internals/hooks/useMaskedInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,20 @@ export const useMaskedInput = <TInputDate, TDate>({
const newParsedValue = rawValue === null ? null : utils.date(rawValue);
const isAcceptedValue = rawValue === null || utils.isValid(newParsedValue);

const innerEqualsParsed =
innerInputValue === null
? newParsedValue === null
: newParsedValue !== null &&
Math.abs(utils.getDiff(innerInputValue, newParsedValue, 'seconds')) === 0;
let innerEqualsParsed = innerInputValue === null && newParsedValue === null; // equal by being both null
if (innerInputValue !== null && newParsedValue !== null) {
const areEqual = utils.isEqual(innerInputValue, newParsedValue);
if (areEqual) {
innerEqualsParsed = true;
} else {
const diff = Math.abs(utils.getDiff(innerInputValue, newParsedValue)); // diff in ms

innerEqualsParsed =
diff === 0
? areEqual // if no diff, use equal to test the time-zone
: diff < 1000; // accept a difference bellow 1s
}
}

if (!localeHasChanged && !inputFormatHasChanged && (!isAcceptedValue || innerEqualsParsed)) {
return;
Expand Down