UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

55 lines (53 loc) 2.25 kB
/** * DevExtreme (cjs/__internal/scheduler/appointments/m_text_utils.js) * Version: 23.2.6 * Build date: Wed May 01 2024 * * Copyright (c) 2012 - 2024 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.getFormatType = exports.formatDates = exports.createFormattedDateText = void 0; var _date = _interopRequireDefault(require("../../../core/utils/date")); var _date2 = _interopRequireDefault(require("../../../localization/date")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } } 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) }; exports.createFormattedDateText = createFormattedDateText; const getFormatType = (startDate, endDate, isAllDay, isDateAndTimeView) => { if (isAllDay) { return "DATE" } if (isDateAndTimeView && _date.default.sameDate(startDate, endDate)) { return "TIME" } return "DATETIME" }; exports.getFormatType = getFormatType; const formatDates = (startDate, endDate, formatType) => { const isSameDate = startDate.getDate() === endDate.getDate(); switch (formatType) { case "DATETIME": return [_date2.default.format(startDate, "monthandday"), " ", _date2.default.format(startDate, "shorttime"), " - ", isSameDate ? "" : "".concat(_date2.default.format(endDate, "monthandday"), " "), _date2.default.format(endDate, "shorttime")].join(""); case "TIME": return "".concat(_date2.default.format(startDate, "shorttime"), " - ").concat(_date2.default.format(endDate, "shorttime")); case "DATE": return "".concat(_date2.default.format(startDate, "monthandday")).concat(isSameDate ? "" : " - ".concat(_date2.default.format(endDate, "monthandday"))) } }; exports.formatDates = formatDates;