1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2026-06-29 20:06:00 -04:00

use date-fns for relative time

This commit is contained in:
2021-12-15 20:28:56 -05:00
parent 11e2a00de5
commit e8c2dcab29
3 changed files with 61 additions and 65 deletions
+16 -14
View File
@@ -1,14 +1,10 @@
import { h } from "preact";
import dayjs from "dayjs";
import dayjsRelativeTime from "dayjs/plugin/relativeTime.js";
import { intlFormat, formatDistanceToNowStrict } from "date-fns";
import parseEmoji from "../utils/parseEmoji.js";
// react components:
import { StarIcon, RepoForkedIcon } from "@primer/octicons-react";
// dayjs plugins: https://day.js.org/docs/en/plugin/loading-into-nodejs
dayjs.extend(dayjsRelativeTime);
const RepositoryCard = (props) => (
<div class="github-card">
<a class="repo-name" href={props.url} target="_blank" rel="noopener noreferrer">
@@ -61,16 +57,22 @@ const RepositoryCard = (props) => (
<div
class="repo-meta-item"
title={new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "short",
day: "numeric",
hour: "numeric",
minute: "numeric",
timeZoneName: "short",
}).format(new Date(props.updatedAt))}
title={intlFormat(
new Date(props.updatedAt),
{
year: "numeric",
month: "short",
day: "numeric",
hour: "numeric",
minute: "numeric",
timeZoneName: "short",
},
{
locale: "en-US",
}
)}
>
<span>Updated {dayjs(props.updatedAt).fromNow()}</span>
<span>Updated {formatDistanceToNowStrict(new Date(props.updatedAt), { addSuffix: true })}</span>
</div>
</div>
</div>