Use locale to format dates and times (#123)

* Use deployment url in demo description.

Close #131
This commit is contained in:
Luke Vella 2022-04-26 20:10:59 +01:00 committed by GitHub
parent 8263926168
commit 8aec24308e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 1240 additions and 864 deletions

View file

@ -7,13 +7,14 @@ import { useMutation } from "react-query";
import Button from "../button";
import { usePoll } from "../poll-context";
import Popover from "../popover";
import { usePreferences } from "../preferences/use-preferences";
export interface PollSubheaderProps {}
const PollSubheader: React.VoidFunctionComponent<PollSubheaderProps> = () => {
const { poll } = usePoll();
const { t } = useTranslation("app");
const { locale } = usePreferences();
const {
mutate: sendVerificationEmail,
isLoading: isSendingVerificationEmail,
@ -29,14 +30,6 @@ const PollSubheader: React.VoidFunctionComponent<PollSubheaderProps> = () => {
t={t}
values={{
name: poll.authorName,
date: Date.parse(poll.createdAt),
formatParams: {
date: {
year: "numeric",
month: "numeric",
day: "numeric",
},
},
}}
components={{
b: <span className="font-medium text-indigo-500" />,
@ -88,7 +81,9 @@ const PollSubheader: React.VoidFunctionComponent<PollSubheaderProps> = () => {
</div>
<span className="hidden md:inline">&nbsp;&bull;&nbsp;</span>
<span className="whitespace-nowrap">
{formatRelative(new Date(poll.createdAt), new Date())}
{formatRelative(new Date(poll.createdAt), new Date(), {
locale,
})}
</span>
</div>
);