UNPKG

@uimkit/uikit-react

Version:

<img style="width:64px" src="https://mgmt.uimkit.chat/media/img/avatar.png"/>

45 lines (42 loc) 1.89 kB
import { isDayOrMoment, isDate, isNumberOrString } from '../context/TranslationContext.js'; import '../context/UIKitContext.js'; import '../context/ComponentContext.js'; import '../context/ChatActionContext.js'; import '../context/MessageInputContext.js'; import '../context/UIMessageContext.js'; import '../context/ChatStateContext.js'; import Dayjs from 'dayjs'; var notValidDateWarning = 'MessageTimestamp was called without a message, or message has invalid created_at date.'; var noParsingFunctionWarning = 'MessageTimestamp was called but there is no datetime parsing function available'; function getDateString(_a) { var calendar = _a.calendar, format = _a.format, _b = _a.formatDate, formatDate = _b === void 0 ? function (date) { return Dayjs(date).fromNow(); } : _b, messageCreatedAt = _a.messageCreatedAt, tDateTimeParser = _a.tDateTimeParser; if (!messageCreatedAt || (typeof messageCreatedAt === 'string' && !Date.parse(messageCreatedAt))) { console.warn(notValidDateWarning); return null; } if (typeof formatDate === 'function') { return formatDate(new Date(messageCreatedAt)); } if (!tDateTimeParser) { console.warn(noParsingFunctionWarning); return null; } var parsedTime = tDateTimeParser(messageCreatedAt); if (isDayOrMoment(parsedTime)) { /** * parsedTime.calendar is guaranteed on the type but is only * available when a user calls dayjs.extend(calendar) */ return calendar && parsedTime.calendar ? parsedTime.calendar() : parsedTime.format(format); } if (isDate(parsedTime)) { return parsedTime.toDateString(); } if (isNumberOrString(parsedTime)) { return parsedTime.toString(); } return null; } export { getDateString, noParsingFunctionWarning, notValidDateWarning }; //# sourceMappingURL=utils.js.map