Skip to content

Commit

Permalink
Little format date naming thing
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewStanciu committed Sep 12, 2023
1 parent 4abb6b7 commit 18e97bc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 31 deletions.
9 changes: 5 additions & 4 deletions components/event-card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format } from 'date-fns'
import { format as formatDate } from 'date-fns'
import Link from 'next/link'
import { past } from '../lib/past'

Expand All @@ -25,14 +25,15 @@ const EventCard = ({
<p className={past(start) ? '' : 'text-black dark:text-black transition'}>
{start === 'TBD'
? 'TBD'
: format(
: formatDate(
new Date(start),
`${past(start) ? 'LLL do, Y •' : 'eee. LLL do •'}`
)}{' '}
{start === 'TBD'
? ''
: format(new Date(start), `h:mm${end === 'TBD' ? ' a' : ''}`) + '—'}
{end === 'TBD' ? '???' : format(new Date(end), 'h:mm a')}
: formatDate(new Date(start), `h:mm${end === 'TBD' ? ' a' : ''}`) +
'—'}
{end === 'TBD' ? '???' : formatDate(new Date(end), 'h:mm a')}
</p>
<h3
className={`${name.length < 30 ? 'text-2xl' : 'text-2xl sm:text-xl'} ${
Expand Down
16 changes: 9 additions & 7 deletions components/past-event.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Head from 'next/head'
import { Clock } from 'react-feather'
import { format } from 'date-fns'
import { formatDate } from '../lib/formatDate'
import { format as formatDate } from 'date-fns'
import { formatDateTz } from '../lib/formatDateTz'
import Nav from './nav'
import Footer from './footer'
import FooterLinks from './footer-links'
Expand All @@ -20,8 +20,8 @@ const PastEvent = ({ event }: { event: PHEvent }) => {
event.name.length < 30 ? '250' : '200'
}px&caption=${
event.start !== 'TBD'
? format(
formatDate(new Date(event.start), 'America/Indianapolis'),
? formatDate(
formatDateTz(new Date(event.start), 'America/Indianapolis'),
'LLL%20d%20•'
)
: ''
Expand Down Expand Up @@ -65,11 +65,13 @@ const PastEvent = ({ event }: { event: PHEvent }) => {
<Clock />
{event.start === 'TBD'
? 'Date TBD'
: format(new Date(event.start), 'LLL do, Y •')}{' '}
: formatDate(new Date(event.start), 'LLL do, Y •')}{' '}
{event.start === 'TBD'
? ''
: format(new Date(event.start), 'h:mm') + '—'}
{event.end === 'TBD' ? '' : format(new Date(event.end), 'h:mm a')}
: formatDate(new Date(event.start), 'h:mm') + '—'}
{event.end === 'TBD'
? ''
: formatDate(new Date(event.end), 'h:mm a')}
</p>
</div>
</div>
Expand Down
14 changes: 7 additions & 7 deletions components/upcoming-event.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Head from 'next/head'
import { Clock, MapPin, Calendar } from 'react-feather'
import { format } from 'date-fns'
import { format as formatDate } from 'date-fns'
import RSVPForm from './rsvp-form'
import StyledLink from './styled-link'
import Footer from './footer'
Expand All @@ -9,7 +9,7 @@ import { footer } from '../lib/footerPonderings'
import { useEffect, useState } from 'react'
import FooterLinks from './footer-links'
import Nav from './nav'
import { formatDate } from '../lib/formatDate'
import { formatDateTz } from '../lib/formatDateTz'
import VercelBanner from './vercel-banner'
import DescriptionBox from './desc-box'

Expand All @@ -27,8 +27,8 @@ const UpcomingEvent = ({ event }: { event: PHEvent }) => {
event.name.includes('Hack Night') ? 'dark' : 'light'
}&md=1&fontSize=${event.name.length < 30 ? '250' : '200'}px&caption=${
event.start !== 'TBD'
? format(
formatDate(new Date(event.start), 'America/Indianapolis'),
? formatDate(
formatDateTz(new Date(event.start), 'America/Indianapolis'),
'LLL%20d%20•'
)
: ''
Expand Down Expand Up @@ -70,19 +70,19 @@ const UpcomingEvent = ({ event }: { event: PHEvent }) => {
<Clock />
{event.start === 'TBD'
? 'Date TBD'
: format(
: formatDate(
new Date(event.start),
`${past(event.start) ? 'LLL do, y' : 'EEEE, LLL do •'}`
)}{' '}
{event.start === 'TBD'
? ''
: format(
: formatDate(
new Date(event.start),
`h:mm${event.end === 'TBD' ? ' a' : ''}`
) + '—'}
{event.end === 'TBD'
? '???'
: format(new Date(event.end), 'h:mm a')}
: formatDate(new Date(event.end), 'h:mm a')}
</p>
<p className="mt-1 text-1xl sm:text-2xl flex flex-row gap-x-1 items-center justify-center dark:text-gray-200">
<MapPin />
Expand Down
8 changes: 4 additions & 4 deletions lib/fetchEvents.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { orderBy } from 'lodash'
import GithubSlugger from 'github-slugger'
import { createClient } from 'next-sanity'
import { format } from 'date-fns'
import { format as formatDate } from 'date-fns'

const client = createClient({
projectId: process.env.SANITY_PROJECT_ID,
Expand All @@ -17,13 +17,13 @@ const getCalLink = (event: SanityEvent) => {
event.name
} (Purdue Hackers)&location=${
event.loc
}&details=A Purdue Hackers Event&dates=${format(
}&details=A Purdue Hackers Event&dates=${formatDate(
new Date(event.start),
'yyyyMMdd'
)}T${format(new Date(event.start), 'HHmm')}00Z%2F${format(
)}T${formatDate(new Date(event.start), 'HHmm')}00Z%2F${formatDate(
new Date(event.end),
'yyyyMMdd'
)}T${format(new Date(event.end), 'HHmm')}00Z`
)}T${formatDate(new Date(event.end), 'HHmm')}00Z`
).href
} catch {
return new URL(
Expand Down
2 changes: 1 addition & 1 deletion lib/formatDate.ts → lib/formatDateTz.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const formatDate = (date: Date, tzString: string) =>
export const formatDateTz = (date: Date, tzString: string) =>
new Date(date.toLocaleString('en-US', { timeZone: tzString }))
16 changes: 8 additions & 8 deletions pages/api/sendReminder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { format } from 'date-fns'
import { format as formatDate } from 'date-fns'
import Mailgun from 'mailgun-js'
import { NextApiRequest, NextApiResponse } from 'next'
import { createClient } from 'next-sanity'

import { fetchEvents } from '../../lib/fetchEvents'
import { formatDate } from '../../lib/formatDate'
import { formatDateTz } from '../../lib/formatDateTz'
import { past } from '../../lib/past'

const client = createClient({
Expand Down Expand Up @@ -92,18 +92,18 @@ const sendEmail = async (
event: PHEvent
): Promise<void> => {
const { name, start, end, loc, slug } = event
const startDate = formatDate(new Date(start), 'America/Indianapolis')
const endDate = formatDate(new Date(end), 'America/Indianapolis')
const startDate = formatDateTz(new Date(start), 'America/Indianapolis')
const endDate = formatDateTz(new Date(end), 'America/Indianapolis')
let parsedStart =
firstOrSecond === 'first'
? format(startDate, 'EEEE') + ' from ' + format(startDate, 'h:mm')
: 'TODAY from ' + format(startDate, 'h:mm')
? formatDate(startDate, 'EEEE') + ' from ' + formatDate(startDate, 'h:mm')
: 'TODAY from ' + formatDate(startDate, 'h:mm')
let parsedEnd
try {
parsedEnd = '—' + format(endDate, 'h:mm a')
parsedEnd = '—' + formatDate(endDate, 'h:mm a')
} catch (err) {
parsedStart =
format(startDate, 'EEEE') + ' at ' + format(startDate, 'h:mm a')
formatDate(startDate, 'EEEE') + ' at ' + formatDate(startDate, 'h:mm a')
parsedEnd = ''
}
console.log('parsed start', parsedStart)
Expand Down

1 comment on commit 18e97bc

@vercel
Copy link

@vercel vercel bot commented on 18e97bc Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.