UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

41 lines (40 loc) 1.78 kB
/** * DevExtreme (esm/__internal/scheduler/appointments/m_text_utils.js) * Version: 24.2.6 * Build date: Mon Mar 17 2025 * * Copyright (c) 2012 - 2025 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 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 "DATE" } if (isDateAndTimeView && dateUtils.sameDate(startDate, endDate)) { return "TIME" } return "DATETIME" }; export const formatDates = (startDate, endDate, formatType) => { const isSameDate = startDate.getDate() === endDate.getDate(); switch (formatType) { case "DATETIME": return [dateLocalization.format(startDate, "monthandday"), " ", dateLocalization.format(startDate, "shorttime"), " - ", isSameDate ? "" : `${dateLocalization.format(endDate,"monthandday")} `, dateLocalization.format(endDate, "shorttime")].join(""); case "TIME": return `${dateLocalization.format(startDate,"shorttime")} - ${dateLocalization.format(endDate,"shorttime")}`; case "DATE": return `${dateLocalization.format(startDate,"monthandday")}${isSameDate?"":` - ${dateLocalization.format(endDate,"monthandday")}`}` } };