UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

56 lines (55 loc) • 2.2 kB
/** * DevExtreme (esm/__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/ */ import dateLocalization from "../../../common/core/localization/date"; import dateUtils from "../../../core/utils/date"; import { getGlobalFormatByDataType } from "../../core/global_format_config"; const formatTooltipDatePart = date => { const globalFormat = getGlobalFormatByDataType("date"); if (globalFormat) { return dateLocalization.format(date, globalFormat) } return String(dateLocalization.format(date, "monthandday")) }; const formatTooltipTimePart = date => { const globalFormat = getGlobalFormatByDataType("time"); if (globalFormat) { return dateLocalization.format(date, globalFormat) } return String(dateLocalization.format(date, "shorttime")) }; 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 [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 "" } };