Skip to content

Commit

Permalink
update short date format
Browse files Browse the repository at this point in the history
  • Loading branch information
vladvelici committed Nov 7, 2024
1 parent 553afc2 commit 9959509
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions demo/src/components/MessageComponent/MessageComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ interface MessageProps {
onMessageDelete?(msg: Message): void;
}

const shortDateTimeFormatter = new Intl.DateTimeFormat('default', {
hour: '2-digit',
minute: '2-digit'
});

const shortDateFullFormatter = new Intl.DateTimeFormat('default', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit'
});

function shortDate(date: Date): string {
if (Date.now() - date.getTime() < 1000 * 60 * 60 * 24) {
// last 24h show the time
return twoDigits(date.getHours()) + ':' + twoDigits(date.getMinutes());
} else {
// older, show full date
return (
date.getDate() +
'/' +
date.getMonth() +
'/' +
date.getFullYear() +
' ' +
twoDigits(date.getHours()) +
':' +
twoDigits(date.getMinutes())
);
return shortDateTimeFormatter.format(date);
}
return shortDateFullFormatter.format(date);
}

export const MessageComponent: React.FC<MessageProps> = ({
Expand Down

0 comments on commit 9959509

Please sign in to comment.