UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

48 lines (47 loc) 2.19 kB
/** * DevExtreme (esm/__internal/scheduler/appointments_new/utils/get_date_text.js) * Version: 25.2.7 * Build date: Tue May 05 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 getDateFormatType = (startDate, endDate, isAllDay, viewType) => { if (isAllDay) { return DateFormatType.DATE } if ("month" !== viewType && dateUtils.sameDate(startDate, endDate)) { return DateFormatType.TIME } return DateFormatType.DATETIME }; export const getDateText = (startDate, endDate, formatType) => { const isSameDate = dateUtils.sameDate(startDate, endDate); 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 "" } }; export 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) };