change news article date formatting
This commit is contained in:
@ -3,7 +3,7 @@ import { Blocks } from "@/components/blocks/Blocks";
|
||||
import Image from "@/components/general/Image";
|
||||
import { graphql } from "@/gql";
|
||||
import { NewsFragment } from "@/gql/graphql";
|
||||
import { compactDateFormat, formatDate } from "@/lib/date";
|
||||
import { formatExtendedDateTime } from "@/lib/date";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
export async function generateStaticParams() {
|
||||
@ -67,7 +67,7 @@ export default async function Page({ params }: { params: { slug: string } }) {
|
||||
)}
|
||||
</figure>
|
||||
)}
|
||||
<p>{formatDate(news.firstPublishedAt, compactDateFormat)}</p>
|
||||
<p>{formatExtendedDateTime(news.firstPublishedAt, true, true)}</p>
|
||||
</section>
|
||||
<section className="pageContent">
|
||||
<Blocks blocks={news.body} />
|
||||
|
@ -1,7 +1,7 @@
|
||||
import styles from "./newsItem.module.scss";
|
||||
import Image from "../general/Image";
|
||||
import { NewsFragment } from "@/lib/news";
|
||||
import { formatDate, compactDateFormat } from "@/lib/date";
|
||||
import { formatDate, compactDateFormat, formatExtendedDateTime } from "@/lib/date";
|
||||
import Link from "next/link";
|
||||
|
||||
export const NewsItem = ({ news }: { news: NewsFragment }) => {
|
||||
@ -22,7 +22,7 @@ export const NewsItem = ({ news }: { news: NewsFragment }) => {
|
||||
</div>
|
||||
<div className={styles.text}>
|
||||
<p className={styles.date}>
|
||||
{formatDate(news.firstPublishedAt, compactDateFormat)}
|
||||
{formatExtendedDateTime(news.firstPublishedAt, true, true)}
|
||||
</p>
|
||||
<h2 className={styles.title}>{news.title}</h2>
|
||||
<p className={styles.lead}>{news.excerpt}</p>
|
||||
|
@ -24,15 +24,18 @@ export function formatYearMonth(yearMonth: string) {
|
||||
return formatDate(parsed, "MMMM yyyy");
|
||||
}
|
||||
|
||||
export function formatExtendedDateTime(date: Date | string | number, dateOnly: boolean = false) {
|
||||
export function formatExtendedDateTime(
|
||||
date: Date | string | number,
|
||||
dateOnly: boolean = false,
|
||||
alwaysIncludeYear: boolean = false
|
||||
) {
|
||||
// wide date with weekday and month name
|
||||
// year included if not current year
|
||||
const parsed = toLocalTime(date);
|
||||
const timePart = dateOnly ? "" : " 'kl.' HH:mm";
|
||||
if (parsed.getFullYear === new Date().getFullYear) {
|
||||
return formatDate(parsed, `EEEE d. MMMM${timePart}`);
|
||||
}
|
||||
return formatDate(parsed, `EEEE d. MMMM yyyy${timePart}`);
|
||||
const isCurrentYear = parsed.getFullYear === new Date().getFullYear;
|
||||
const yearPart = isCurrentYear && !alwaysIncludeYear ? "" : " yyyy";
|
||||
return formatDate(parsed, `EEEE d. MMMM${yearPart}${timePart}`);
|
||||
}
|
||||
|
||||
export function isTodayOrFuture(
|
||||
|
Reference in New Issue
Block a user