|
|
|
@ -5,16 +5,18 @@ import isToday from 'Utilities/Date/isToday';
|
|
|
|
|
import isTomorrow from 'Utilities/Date/isTomorrow';
|
|
|
|
|
import isYesterday from 'Utilities/Date/isYesterday';
|
|
|
|
|
import translate from 'Utilities/String/translate';
|
|
|
|
|
import formatDateTime from './formatDateTime';
|
|
|
|
|
|
|
|
|
|
function getRelativeDate(date, shortDateFormat, showRelativeDates, { timeFormat, includeSeconds = false, timeForToday = false } = {}) {
|
|
|
|
|
function getRelativeDate(date, shortDateFormat, showRelativeDates, { timeFormat, includeSeconds = false, timeForToday = false, includeTime = false } = {}) {
|
|
|
|
|
if (!date) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isTodayDate = isToday(date);
|
|
|
|
|
const time = formatTime(date, timeFormat, { includeMinuteZero: true, includeSeconds });
|
|
|
|
|
|
|
|
|
|
if (isTodayDate && timeForToday && timeFormat) {
|
|
|
|
|
return formatTime(date, timeFormat, { includeMinuteZero: true, includeSeconds });
|
|
|
|
|
return time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!showRelativeDates) {
|
|
|
|
@ -22,22 +24,26 @@ function getRelativeDate(date, shortDateFormat, showRelativeDates, { timeFormat,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isYesterday(date)) {
|
|
|
|
|
return translate('Yesterday');
|
|
|
|
|
return includeTime ? translate('YesterdayAt', { time } ): translate('Yesterday');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isTodayDate) {
|
|
|
|
|
return translate('Today');
|
|
|
|
|
return includeTime ? translate('TodayAt', { time } ): translate('Today');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isTomorrow(date)) {
|
|
|
|
|
return translate('Tomorrow');
|
|
|
|
|
return includeTime ? translate('TomorrowAt', { time } ): translate('Tomorrow');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isInNextWeek(date)) {
|
|
|
|
|
return moment(date).format('dddd');
|
|
|
|
|
const day = moment(date).format('dddd');
|
|
|
|
|
|
|
|
|
|
return includeTime ? translate('DayOfWeekAt', { day, time }) : day;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return moment(date).format(shortDateFormat);
|
|
|
|
|
return includeTime ?
|
|
|
|
|
formatDateTime(date, shortDateFormat, timeFormat, { includeSeconds }) :
|
|
|
|
|
moment(date).format(shortDateFormat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default getRelativeDate;
|
|
|
|
|