Skip to content

Commit

Permalink
moment timestamp formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Puyodead1 committed Aug 9, 2023
1 parent 80ae865 commit 8b61b80
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"react-error-boundary": "^3.1.4",
"react-hook-form": "^7.43.9",
"react-loading-skeleton": "^3.3.1",
"react-moment": "^1.1.3",
"react-router-dom": "^6.11.1",
"react-scripts": "5.0.1",
"react-secure-storage": "^1.2.2",
Expand Down
23 changes: 23 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/components/Message.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Moment from "react-moment";
import styled from "styled-components";
import { QueuedMessage } from "../stores/MessageQueue";
import { default as MessageObject } from "../stores/objects/Message";
import { calendarStrings } from "../utils/i18n";
import Avatar from "./Avatar";

type MessageLike = MessageObject | QueuedMessage;
Expand Down Expand Up @@ -74,7 +76,10 @@ function Message({ message, isHeader, isSending, isFailed }: Props) {
</MessageAuthor>

<MessageTimestamp>
{message.timestamp.toLocaleTimeString()}
<Moment
calendar={calendarStrings}
date={new Date(message.timestamp)}
/>
</MessageTimestamp>
</MessageHeader>
)}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const calendarStrings = {
lastDay: "[Yesterday at] LT",
nextDay: "[Tomorrow at] LT",
sameDay: "[Today at] LT",
sameElse: "MM/DD/YYYY LT",
};

0 comments on commit 8b61b80

Please sign in to comment.