Skip to content

Commit

Permalink
[pickers] Update pickers when new value has a distinct timezone (#7853)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette authored Feb 9, 2023
1 parent 68fe697 commit c6ab151
Showing 1 changed file with 14 additions and 5 deletions.
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

0 comments on commit c6ab151

Please sign in to comment.