UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

77 lines (75 loc) 3.17 kB
/** * DevExtreme (cjs/__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/ */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDateTextFromTargetAppointment = exports.getDateText = exports.getDateFormatType = exports.DateFormatType = void 0; var _date = _interopRequireDefault(require("../../../../common/core/localization/date")); var _date2 = _interopRequireDefault(require("../../../../core/utils/date")); var _m_global_format_config = require("../../../core/m_global_format_config"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e } } const formatTooltipDatePart = date => { const globalFormat = (0, _m_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, _m_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; 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) }; exports.getDateTextFromTargetAppointment = getDateTextFromTargetAppointment;