devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
65 lines (64 loc) • 2.61 kB
JavaScript
/**
* DevExtreme (esm/__internal/scheduler/appointments_new/utils/get_date_text.js)
* Version: 26.1.3
* Build date: Wed Jun 10 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import dateLocalization from "../../../../common/core/localization/date";
import dateUtils from "../../../../core/utils/date";
import {
getGlobalFormatByDataType
} from "../../../core/m_global_format_config";
const formatTooltipDatePart = date => {
const globalFormat = getGlobalFormatByDataType("date");
if (globalFormat) {
return dateLocalization.format(date, globalFormat)
}
return String(dateLocalization.format(date, "monthandday"))
};
const formatTooltipTimePart = date => {
const globalFormat = getGlobalFormatByDataType("time");
if (globalFormat) {
return dateLocalization.format(date, globalFormat)
}
return String(dateLocalization.format(date, "shorttime"))
};
export var DateFormatType;
! function(DateFormatType) {
DateFormatType.DATETIME = "DATETIME";
DateFormatType.TIME = "TIME";
DateFormatType.DATE = "DATE"
}(DateFormatType || (DateFormatType = {}));
export const getDateFormatType = (startDate, endDate, isAllDay, viewType) => {
if (isAllDay) {
return DateFormatType.DATE
}
if ("month" !== viewType && dateUtils.sameDate(startDate, endDate)) {
return DateFormatType.TIME
}
return DateFormatType.DATETIME
};
export const getDateText = (startDate, endDate, formatType) => {
const isSameDate = dateUtils.sameDate(startDate, endDate);
switch (formatType) {
case DateFormatType.DATETIME:
return [formatTooltipDatePart(startDate), formatTooltipTimePart(startDate), "-", !isSameDate && formatTooltipDatePart(endDate), formatTooltipTimePart(endDate)].filter(Boolean).join(" ");
case DateFormatType.TIME:
return `${formatTooltipTimePart(startDate)} - ${formatTooltipTimePart(endDate)}`;
case DateFormatType.DATE:
return `${formatTooltipDatePart(startDate)}${isSameDate?"":` - ${formatTooltipDatePart(endDate)}`}`;
default:
return ""
}
};
export const getDateTextFromTargetAppointment = (targetedAppointmentData, format, viewType) => {
const {
displayStartDate: startDate,
displayEndDate: endDate,
allDay: allDay
} = targetedAppointmentData;
const formatType = format ?? getDateFormatType(startDate, endDate, allDay, viewType);
return getDateText(startDate, endDate, formatType)
};