devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
49 lines (48 loc) • 2.11 kB
JavaScript
/**
* DevExtreme (esm/__internal/scheduler/appointments/m_text_utils.js)
* Version: 25.2.5
* Build date: Fri Feb 20 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";
export var DateFormatType;
! function(DateFormatType) {
DateFormatType.DATETIME = "DATETIME";
DateFormatType.TIME = "TIME";
DateFormatType.DATE = "DATE"
}(DateFormatType || (DateFormatType = {}));
export const createFormattedDateText = options => {
const {
startDate: startDate,
endDate: endDate,
allDay: allDay,
format: format
} = options;
const formatType = format || getFormatType(startDate, endDate, allDay);
return formatDates(startDate, endDate, formatType)
};
export const getFormatType = (startDate, endDate, isAllDay, isDateAndTimeView) => {
if (isAllDay) {
return DateFormatType.DATE
}
if (isDateAndTimeView && dateUtils.sameDate(startDate, endDate)) {
return DateFormatType.TIME
}
return DateFormatType.DATETIME
};
export const formatDates = (startDate, endDate, formatType) => {
const isSameDate = startDate.getDate() === endDate.getDate();
switch (formatType) {
case DateFormatType.DATETIME:
return [dateLocalization.format(startDate, "monthandday"), " ", dateLocalization.format(startDate, "shorttime"), " - ", isSameDate ? "" : `${dateLocalization.format(endDate,"monthandday")} `, dateLocalization.format(endDate, "shorttime")].join("");
case DateFormatType.TIME:
return `${dateLocalization.format(startDate,"shorttime")} - ${dateLocalization.format(endDate,"shorttime")}`;
case DateFormatType.DATE:
return `${dateLocalization.format(startDate,"monthandday")}${isSameDate?"":` - ${dateLocalization.format(endDate,"monthandday")}`}`;
default:
return
}
};