devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
67 lines (65 loc) • 2.64 kB
JavaScript
/**
* DevExtreme (cjs/__internal/scheduler/utils/get_date_text.js)
* Version: 26.1.6
* Build date: Fri Oct 16 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getDateText = exports.getDateFormatType = exports.DateFormatType = void 0;
var _date = _interopRequireDefault(require("../../../common/core/localization/date"));
var _date2 = _interopRequireDefault(require("../../../core/utils/date"));
var _global_format_config = require("../../core/global_format_config");
function _interopRequireDefault(e) {
return e && e.__esModule ? e : {
default: e
}
}
const formatTooltipDatePart = date => {
const globalFormat = (0, _global_format_config.getGlobalFormatByDataType)("date");
if (globalFormat) {
return _date.default.format(date, globalFormat)
}
return String(_date.default.format(date, "monthandday"))
};
const formatTooltipTimePart = date => {
const globalFormat = (0, _global_format_config.getGlobalFormatByDataType)("time");
if (globalFormat) {
return _date.default.format(date, globalFormat)
}
return String(_date.default.format(date, "shorttime"))
};
var DateFormatType;
! function(DateFormatType) {
DateFormatType.DATETIME = "DATETIME";
DateFormatType.TIME = "TIME";
DateFormatType.DATE = "DATE"
}(DateFormatType || (exports.DateFormatType = DateFormatType = {}));
const getDateFormatType = (startDate, endDate, isAllDay, viewType) => {
if (isAllDay) {
return DateFormatType.DATE
}
if ("month" !== viewType && _date2.default.sameDate(startDate, endDate)) {
return DateFormatType.TIME
}
return DateFormatType.DATETIME
};
exports.getDateFormatType = getDateFormatType;
const getDateText = (startDate, endDate, formatType) => {
const isSameDate = _date2.default.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 ""
}
};
exports.getDateText = getDateText;