Этот коммит содержится в:
Harshil Sharma
2024-11-13 12:47:48 +05:30
коммит произвёл GitHub
родитель c79a8a8b4a
Коммит b0ee1627f0
2 изменённых файлов: 15 добавлений и 8 удалений

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

@@ -31,8 +31,6 @@ import {getCurrentMomentForTimezone} from 'utils/timezone';
const CUSTOM_STATUS_TIME_PICKER_INTERVALS_IN_MINUTES = 30; const CUSTOM_STATUS_TIME_PICKER_INTERVALS_IN_MINUTES = 30;
const DATE_FORMAT = 'yyyy-MM-dd';
export function getRoundedTime(value: Moment, roundedTo = CUSTOM_STATUS_TIME_PICKER_INTERVALS_IN_MINUTES) { export function getRoundedTime(value: Moment, roundedTo = CUSTOM_STATUS_TIME_PICKER_INTERVALS_IN_MINUTES) {
const start = moment(value); const start = moment(value);
const diff = start.minute() % roundedTo; const diff = start.minute() % roundedTo;
@@ -118,12 +116,16 @@ const DateTimeInputContainer: React.FC<Props> = ({
const handleDayChange = (day: Date, modifiers: DayModifiers) => { const handleDayChange = (day: Date, modifiers: DayModifiers) => {
if (modifiers.today) { if (modifiers.today) {
const currentTime = getCurrentMomentForTimezone(timezone); const baseTime = getCurrentMomentForTimezone(timezone);
const roundedTime = getRoundedTime(currentTime, timePickerInterval); baseTime.hour(time.hours());
baseTime.minute(time.minutes());
const roundedTime = getRoundedTime(baseTime, timePickerInterval);
handleChange(roundedTime); handleChange(roundedTime);
} else { } else {
day.setHours(time.hour(), time.minute());
const dayWithTimezone = timezone ? moment(day).tz(timezone, true) : moment(day); const dayWithTimezone = timezone ? moment(day).tz(timezone, true) : moment(day);
handleChange(dayWithTimezone.startOf('day')); handleChange(dayWithTimezone);
} }
handlePopperOpenState(false); handlePopperOpenState(false);
}; };
@@ -148,7 +150,7 @@ const DateTimeInputContainer: React.FC<Props> = ({
}, []); }, []);
const formatDate = (date: Moment): string => { const formatDate = (date: Moment): string => {
return relativeDate ? relativeFormatDate(date, formatMessage, DATE_FORMAT) : DateTime.fromJSDate(date.toDate()).toFormat(DATE_FORMAT); return relativeDate ? relativeFormatDate(date, formatMessage) : DateTime.fromJSDate(date.toDate()).toLocaleString();
}; };
const inputIcon = ( const inputIcon = (

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

@@ -90,7 +90,7 @@ export function toUTCUnix(date: Date): number {
return Math.round(new Date(date.toISOString()).getTime() / 1000); return Math.round(new Date(date.toISOString()).getTime() / 1000);
} }
export function relativeFormatDate(date: Moment, formatMessage: ReturnType<typeof useIntl>['formatMessage'], format = 'yyyy-MM-dd'): string { export function relativeFormatDate(date: Moment, formatMessage: ReturnType<typeof useIntl>['formatMessage'], format?: string): string {
const now = moment(); const now = moment();
const inputDate = moment(date); const inputDate = moment(date);
@@ -101,5 +101,10 @@ export function relativeFormatDate(date: Moment, formatMessage: ReturnType<typeo
} else if (inputDate.isSame(now.clone().add(1, 'days'), 'day')) { } else if (inputDate.isSame(now.clone().add(1, 'days'), 'day')) {
return formatMessage({id: 'date_separator.tomorrow', defaultMessage: 'Tomorrow'}); return formatMessage({id: 'date_separator.tomorrow', defaultMessage: 'Tomorrow'});
} }
return DateTime.fromJSDate(date.toDate()).toFormat(format);
if (format) {
return DateTime.fromJSDate(date.toDate()).toFormat(format);
}
return DateTime.fromJSDate(date.toDate()).toLocaleString();
} }