UNPKG

stream-chat-react-native-core

Version:

The official React Native and Expo components for Stream Chat, a service for building chat applications

75 lines 2.43 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.getDateString = getDateString; exports.noParsingFunctionWarning = exports.getDateStringForA11y = void 0; var _calendarFormats = require("./calendarFormats"); var _isDayOrMoment = require("../../contexts/translationContext/isDayOrMoment"); var noParsingFunctionWarning = exports.noParsingFunctionWarning = 'MessageTimestamp was called but there is no datetime parsing function available'; function getDateString({ calendar, calendarFormats, date, format, t, tDateTimeParser, timestampTranslationKey }) { if (!date || typeof date === 'string' && !Date.parse(date)) { return; } if (!tDateTimeParser) { console.log(noParsingFunctionWarning); return; } if (t && timestampTranslationKey) { var options = {}; if (typeof calendar !== 'undefined' && calendar !== null) { options.calendar = calendar; } if (typeof calendarFormats !== 'undefined' && calendarFormats !== null) { options.calendarFormats = calendarFormats; } if (typeof format !== 'undefined' && format !== null) { options.format = format; } var translatedTimestamp = t(timestampTranslationKey, { ...options, timestamp: new Date(date) }); var translationKeyFound = timestampTranslationKey !== translatedTimestamp; if (translationKeyFound) { return translatedTimestamp; } } var parsedTime = tDateTimeParser(date); if ((0, _isDayOrMoment.isDayOrMoment)(parsedTime)) { return calendar && parsedTime.calendar ? parsedTime.calendar(undefined, calendarFormats) : parsedTime.format(format); } return new Date(date).toDateString(); } var getDateStringForA11y = ({ calendarFormatOverrides, date, tDateTimeParser, userLanguage }) => { if (!date || typeof date === 'string' && !Date.parse(date)) { return undefined; } if (!tDateTimeParser) { return undefined; } var parsedTime = tDateTimeParser(date); if (!(0, _isDayOrMoment.isDayOrMoment)(parsedTime) || !parsedTime.calendar) { return undefined; } var localeFormats = userLanguage && _calendarFormats.calendarFormats[userLanguage] || _calendarFormats.calendarFormats.en; return parsedTime.calendar(undefined, { ...localeFormats, sameElse: 'LL', ...calendarFormatOverrides }); }; exports.getDateStringForA11y = getDateStringForA11y; //# sourceMappingURL=getDateString.js.map