Skip to content
Open
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
3 changes: 2 additions & 1 deletion frontend/components/article/ArticleMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from "react";
import ArticleActions from "./ArticleActions";
import CustomImage from "../common/CustomImage";
import CustomLink from "../common/CustomLink";
import formatDate from "../../lib/utils/formatDate";

const ArticleMeta = ({ article }) => {
if (!article) return;
Expand All @@ -25,7 +26,7 @@ const ArticleMeta = ({ article }) => {
{article.author?.username}
</CustomLink>
<span className="date">
{new Date(article.createdAt).toDateString()}
{formatDate(article.createdAt)}
</span>
</div>

Expand Down
3 changes: 2 additions & 1 deletion frontend/components/article/ArticlePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import CustomImage from "../common/CustomImage";
import { usePageDispatch } from "../../lib/context/PageContext";
import checkLogin from "../../lib/utils/checkLogin";
import { SERVER_BASE_URL } from "../../lib/utils/constant";
import formatDate from "../../lib/utils/formatDate";
import storage from "../../lib/utils/storage";

const FAVORITED_CLASS = "btn btn-sm btn-primary";
Expand Down Expand Up @@ -91,7 +92,7 @@ const ArticlePreview = ({ article }) => {
<span onClick={() => setPage(0)}>{preview.author.username}</span>
</CustomLink>
<span className="date">
{new Date(preview.createdAt).toDateString()}
{formatDate(preview.createdAt)}
</span>
</div>

Expand Down
3 changes: 2 additions & 1 deletion frontend/components/comment/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import CustomImage from "../common/CustomImage";
import Maybe from "../common/Maybe";
import DeleteButton from "./DeleteButton";
import checkLogin from "../../lib/utils/checkLogin";
import formatDate from "../../lib/utils/formatDate";
import storage from "../../lib/utils/storage";

const Comment = ({ comment }) => {
Expand Down Expand Up @@ -40,7 +41,7 @@ const Comment = ({ comment }) => {
{comment.author.username}
</CustomLink>
<span className="date-posted">
{new Date(comment.createdAt).toDateString()}
{formatDate(comment.createdAt)}
</span>
<Maybe test={canModify}>
<DeleteButton commentId={comment.id} />
Expand Down
8 changes: 8 additions & 0 deletions frontend/lib/utils/formatDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const formatDate = (iso: string): string =>
new Date(iso).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric"
});

export default formatDate;
Loading