MM-55192: Fix datepicker hand on DST dates (#28694)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f10ae31422
Коммит
aaf9234c8e
@@ -12,7 +12,7 @@ import * as i18Selectors from 'selectors/i18n';
|
|||||||
|
|
||||||
import mockStore from 'tests/test_store';
|
import mockStore from 'tests/test_store';
|
||||||
|
|
||||||
import DateTimeInput from './date_time_input';
|
import DateTimeInput, {getTimeInIntervals} from './date_time_input';
|
||||||
|
|
||||||
jest.mock('selectors/i18n');
|
jest.mock('selectors/i18n');
|
||||||
|
|
||||||
@@ -34,4 +34,17 @@ describe('components/custom_status/date_time_input', () => {
|
|||||||
);
|
);
|
||||||
expect(wrapper.dive()).toMatchSnapshot();
|
expect(wrapper.dive()).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
['2024-03-02T02:00:00+0100', 48],
|
||||||
|
['2024-03-31T02:00:00+0100', 46],
|
||||||
|
['2024-10-07T02:00:00+0100', 48],
|
||||||
|
['2024-10-27T02:00:00+0100', 48],
|
||||||
|
['2025-01-01T03:00:00+0200', 48],
|
||||||
|
])('should not infinitely loop on DST', (time, expected) => {
|
||||||
|
const timezone = 'Europe/Paris';
|
||||||
|
|
||||||
|
const intervals = getTimeInIntervals(moment.tz(time, timezone).startOf('day'));
|
||||||
|
expect(intervals).toHaveLength(expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -40,14 +40,21 @@ export function getRoundedTime(value: Moment) {
|
|||||||
return start.add(remainder, 'm').seconds(0).milliseconds(0);
|
return start.add(remainder, 'm').seconds(0).milliseconds(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const getTimeInIntervals = (startTime: Moment): Date[] => {
|
export const getTimeInIntervals = (startTime: Moment): Date[] => {
|
||||||
const interval = CUSTOM_STATUS_TIME_PICKER_INTERVALS_IN_MINUTES;
|
const interval = CUSTOM_STATUS_TIME_PICKER_INTERVALS_IN_MINUTES;
|
||||||
let time = moment(startTime);
|
let time = moment(startTime);
|
||||||
const nextDay = moment(startTime).add(1, 'days').startOf('day');
|
const nextDay = moment(startTime).add(1, 'days').startOf('day');
|
||||||
|
|
||||||
const intervals: Date[] = [];
|
const intervals: Date[] = [];
|
||||||
while (time.isBefore(nextDay)) {
|
while (time.isBefore(nextDay)) {
|
||||||
intervals.push(time.toDate());
|
intervals.push(time.toDate());
|
||||||
|
const utcOffset = time.utcOffset();
|
||||||
time = time.add(interval, 'minutes').seconds(0).milliseconds(0);
|
time = time.add(interval, 'minutes').seconds(0).milliseconds(0);
|
||||||
|
|
||||||
|
// Account for DST end if needed to avoid displaying duplicates
|
||||||
|
if (utcOffset > time.utcOffset()) {
|
||||||
|
time = time.add(utcOffset - time.utcOffset(), 'minutes').seconds(0).milliseconds(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return intervals;
|
return intervals;
|
||||||
@@ -113,7 +120,7 @@ const DateTimeInputContainer: React.FC<Props> = (props: Props) => {
|
|||||||
|
|
||||||
const handleTimeChange = useCallback((time: Date, e: React.MouseEvent) => {
|
const handleTimeChange = useCallback((time: Date, e: React.MouseEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
handleChange(moment(time));
|
handleChange(timezone ? moment.tz(time, timezone) : moment(time));
|
||||||
focusTimeButton();
|
focusTimeButton();
|
||||||
}, [handleChange]);
|
}, [handleChange]);
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user