Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/>
/>
showTime: boolean
) {
if (isNaN(timestamp)) {
return '';
}
const now = new Date();
const that = new Date(timestamp);
const locale = i18n.locale;
const options: Intl.DateTimeFormatOptions = {
};
const isSameDay = sameDay(now, that);
const isSameWeek = sameWeek(now, that);
const timeStr = (isSameDay || showTime) ? that.toLocaleTimeString(locale, {
hour: 'numeric',
minute: 'numeric',
hour12: RNLocalize.uses24HourClock(),
}) : '';
const dayStr = isSameDay ? '' : isSameWeek ? that.toLocaleDateString(locale, {
weekday: 'long',
}) : that.toLocaleDateString(locale, {
year: 'numeric',
month: showTime ? 'short' : 'numeric',
day: 'numeric',
});
return [dayStr, timeStr].filter(i => i.length > 0).join(' ');
}