29 lines
704 B
TypeScript
29 lines
704 B
TypeScript
'use client'
|
|
|
|
import { format, isWithinInterval } from "date-fns";
|
|
import type { EventsDate } from "./types";
|
|
|
|
const events: EventsDate[] = [
|
|
{
|
|
name: 'christmas',
|
|
start: [12, 20],
|
|
end: [12, 32]
|
|
},
|
|
]
|
|
|
|
export function getExpirationDate () {
|
|
const expirationDate = new Date("2026-02-15");
|
|
return format(expirationDate, "dddd, D MMMM YYYY");
|
|
}
|
|
|
|
export function getEvent (): EventsDate | undefined {
|
|
return events.find((e) => {
|
|
const today = new Date(Date.now());
|
|
const year = today.getFullYear();
|
|
|
|
const start = new Date(year, e.start[0] - 1, e.start[1]);
|
|
const end = new Date(year, e.end[0] - 1, e.end[1]);
|
|
|
|
return isWithinInterval(today, { start, end })
|
|
})
|
|
} |