Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ export const ChatMessageInfo = ({
<p>
{t('Created')}:
{formatDateExludingYearIfCurrent(
new Date(msg.fileMetadata.appData.userDate || msg.fileMetadata.created)
new Date(msg.fileMetadata.appData.userDate || msg.fileMetadata.created),
true
)}
</p>

{msg.fileMetadata.updated !== msg.fileMetadata.created ? (
<p>
{t('Updated')}: {formatDateExludingYearIfCurrent(new Date(msg.fileMetadata.updated))}
{t('Updated')}:{' '}
{formatDateExludingYearIfCurrent(new Date(msg.fileMetadata.updated), true)}
</p>
) : null}
{msg.fileMetadata.transitCreated ? (
Expand Down
20 changes: 15 additions & 5 deletions packages/common/common-app/src/helpers/timeago/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const formatToTimeAgo = (date: TDate, locale = 'en_short', opts?: Opts):
export const formatToTimeAgoWithRelativeDetail = (
date: Date | undefined,
keepDetailWhenIncludesDate?: boolean,
ignoreTimeOfDay?: boolean
ignoreTimeOfDay?: boolean,
showSeconds?: boolean
): string | undefined => {
if (!date) return undefined;

Expand All @@ -38,6 +39,7 @@ export const formatToTimeAgoWithRelativeDetail = (
const timeFormat: Intl.DateTimeFormatOptions = {
hour: 'numeric',
minute: 'numeric',
second: showSeconds ? 'numeric' : undefined,
};
return date.toLocaleTimeString(undefined, timeFormat);
}
Expand Down Expand Up @@ -71,11 +73,15 @@ export const formatToTimeAgoWithRelativeDetail = (
year: yearsAgo !== 0 ? 'numeric' : undefined,
hour: keepDetailWhenIncludesDate ? 'numeric' : undefined,
minute: keepDetailWhenIncludesDate ? 'numeric' : undefined,
second: keepDetailWhenIncludesDate && showSeconds ? 'numeric' : undefined,
};
return date.toLocaleDateString(undefined, dateTimeFormat);
};

export const formatToDateAgoWithRelativeDetail = (date: Date | undefined): string | undefined => {
export const formatToDateAgoWithRelativeDetail = (
date: Date | undefined,
showSeconds?: boolean
): string | undefined => {
if (!date) return undefined;

// if date is this week
Expand Down Expand Up @@ -117,17 +123,21 @@ export const formatToDateAgoWithRelativeDetail = (date: Date | undefined): strin
day: 'numeric',
month: 'short',
year: yearsAgo !== 0 ? 'numeric' : undefined,
second: showSeconds ? 'numeric' : undefined,
};
return date.toLocaleDateString(undefined, dateTimeFormat);
};

const dateFormat: Intl.DateTimeFormatOptions = {
const getDateFormat = (showSeconds?: boolean): Intl.DateTimeFormatOptions => ({
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
};
export const formatDateExludingYearIfCurrent = (date: Date) => {
second: showSeconds ? 'numeric' : undefined,
});

export const formatDateExludingYearIfCurrent = (date: Date, showSeconds?: boolean) => {
const dateFormat = getDateFormat(showSeconds);
const now = new Date();
if (now.getFullYear() === date.getFullYear()) {
return date.toLocaleDateString(undefined, dateFormat);
Expand Down
Loading