Skip to content

Commit

Permalink
Use browser time formatting instead of Moment
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn-Signal committed Feb 23, 2022
1 parent 3ad6ff7 commit 1f19140
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions ts/util/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,12 @@ export function formatDateTimeShort(
const now = Date.now();
const diff = now - timestamp;

if (diff < MINUTE) {
return i18n('justNow');
}

if (diff < HOUR) {
return i18n('minutesAgo', [Math.floor(diff / MINUTE).toString()]);
if (diff < HOUR || isToday(timestamp)) {
return formatTime(i18n, rawTimestamp);
}

const m = moment(timestamp);

if (isToday(timestamp)) {
return m.format('LT');
}

if (diff < WEEK && m.isSame(now, 'month')) {
return m.format('ddd');
}
Expand Down Expand Up @@ -123,7 +115,10 @@ export function formatTime(
return i18n('minutesAgo', [Math.floor(diff / MINUTE).toString()]);
}

return moment(timestamp).format('LT');
return new Date(timestamp).toLocaleTimeString([], {
hour: 'numeric',
minute: '2-digit',
});
}

export function formatDate(
Expand Down

0 comments on commit 1f19140

Please sign in to comment.