mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-11-14 23:20:51 -05:00
dayjs ➡️ date-fns
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
import { formatDate } from "../../lib/helpers/format-date";
|
||||
import { format, formatISO } from "date-fns";
|
||||
import { enUS } from "date-fns/locale";
|
||||
import { tz } from "@date-fns/tz";
|
||||
import { utc } from "@date-fns/utc";
|
||||
import * as config from "../../lib/config";
|
||||
import type { ComponentPropsWithoutRef } from "react";
|
||||
|
||||
export type TimeProps = ComponentPropsWithoutRef<"time"> & {
|
||||
date: string | number | Date;
|
||||
date: string;
|
||||
format?: string;
|
||||
};
|
||||
|
||||
const Time = ({ date, format = "MMM D", ...rest }: TimeProps) => {
|
||||
const Time = ({ date, format: formatStr = "PPpp", ...rest }: TimeProps) => {
|
||||
return (
|
||||
<time dateTime={formatDate(date)} title={formatDate(date, "MMM D, YYYY, h:mm A z")} {...rest}>
|
||||
{formatDate(date, format)}
|
||||
<time
|
||||
dateTime={formatISO(date, { in: utc })}
|
||||
title={format(date, "MMM d, y, h:mm a O", { in: tz(config.timeZone), locale: enUS })}
|
||||
{...rest}
|
||||
>
|
||||
{format(date, formatStr, { in: tz(config.timeZone), locale: enUS })}
|
||||
</time>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user