MM-61782 - fix invalid time when changing to today after 9 am (#29287)

* MM-61782 - fix invalid time when changing to today after 9 am

* reset time interval to correct value

* Updated time reset logic

---------

Co-authored-by: Harshil Sharma <harshil.sharma@mattermost.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Pablo Vélez
2024-11-18 11:25:32 +01:00
коммит произвёл GitHub
родитель 7f032b0b39
Коммит ce3d2ec761
2 изменённых файлов: 13 добавлений и 4 удалений

Просмотреть файл

@@ -27,7 +27,7 @@ import type {A11yFocusEventDetail} from 'utils/constants';
import Constants, {A11yCustomEventTypes} from 'utils/constants';
import {relativeFormatDate} from 'utils/datetime';
import {isKeyPressed} from 'utils/keyboard';
import {getCurrentMomentForTimezone} from 'utils/timezone';
import {getCurrentMomentForTimezone, isBeforeTime} from 'utils/timezone';
const CUSTOM_STATUS_TIME_PICKER_INTERVALS_IN_MINUTES = 30;
@@ -117,9 +117,10 @@ const DateTimeInputContainer: React.FC<Props> = ({
const handleDayChange = (day: Date, modifiers: DayModifiers) => {
if (modifiers.today) {
const baseTime = getCurrentMomentForTimezone(timezone);
baseTime.hour(time.hours());
baseTime.minute(time.minutes());
if (isBeforeTime(baseTime, time)) {
baseTime.hour(time.hours());
baseTime.minute(time.minutes());
}
const roundedTime = getRoundedTime(baseTime, timePickerInterval);
handleChange(roundedTime);
} else {

Просмотреть файл

@@ -1,6 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import type {Moment} from 'moment-timezone';
import moment from 'moment-timezone';
export function getBrowserTimezone() {
@@ -28,3 +29,10 @@ export function getCurrentDateTimeForTimezone(timezone: string) {
export function getCurrentMomentForTimezone(timezone?: string) {
return timezone ? moment.tz(timezone) : moment();
}
export function isBeforeTime(dateTime1: Moment, dateTime2: Moment) {
const a = dateTime1.clone().set({year: 0, month: 0, date: 1});
const b = dateTime2.clone().set({year: 0, month: 0, date: 1});
return a.isBefore(b);
}