import { CalendarDaysIcon, ClockIcon, MapPinIcon, } from '@heroicons/react/24/outline'; import { getDate, getMonth, isSameDay, parseISO } from 'date-fns'; import React from 'react'; import { Badge } from '../../Badge/index'; import { Link } from '../../Link/Link'; interface Tags { category: { id: number; name: string; slug: string }[]; audience: { id: number; name: string; slug: string }[]; } export interface EventCardProps { title?: string; heading?: 'h2' | 'h3'; link: string; startDateTime: string; endDateTime: string; featuredImage?: string; description?: string; onCampus: boolean; onCampusBuilding?: string | null; onCampusRoomNumber?: string | null; eventAddress?: string; tags?: Tags; } export const EventCard = ({ title, heading: HeadLevel = 'h3', link, startDateTime, endDateTime, featuredImage, onCampus, onCampusBuilding, onCampusRoomNumber, eventAddress, tags, }: EventCardProps) => { const defaultImage = 'https://images.unsplash.com/photo-1496128858413-b36217c2ce36?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1200&q=80'; const getMonthName = (month: any, short: boolean = false) => { const d = new Date(); d.setMonth(month); const monthName = d.toLocaleString('default', { month: short ? 'short' : 'long', }); return monthName; }; const formatTime = (date: any) => { var hours = date.getHours(); var minutes = date.getMinutes(); var ampm = hours >= 12 ? 'PM' : 'AM'; hours = hours % 12; hours = hours ? hours : 12; minutes = minutes < 10 ? '0' + minutes : minutes; var strTime = hours + ':' + minutes + ' ' + ampm; return strTime; }; const startDate = parseISO(startDateTime); const endDate = parseISO(endDateTime); const eventStartDate = getDate(startDate); const eventStartMonth = getMonth(startDate); const eventEndDate = getDate(endDate); const isEventSameDay = isSameDay(startDate, endDate); const multiDayDisplay = () => { if (!isEventSameDay) { return ( ); } else { return ( ); } }; return (
{getMonthName(eventStartMonth, true)}
{eventStartDate}