Skip to content

Commit

Permalink
Merge pull request #57 from purduehackers/matthew/clearer-time-format…
Browse files Browse the repository at this point in the history
…ting

Clearer time formatting for Hack Night
  • Loading branch information
MatthewStanciu authored Sep 12, 2023
2 parents 18e97bc + f176efd commit 7db4dd5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
3 changes: 2 additions & 1 deletion components/event-card.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { format as formatDate } from 'date-fns'
import Link from 'next/link'
import { startTimeFormatString } from '../lib/formatDate'
import { past } from '../lib/past'

const EventCard = ({
Expand Down Expand Up @@ -31,7 +32,7 @@ const EventCard = ({
)}{' '}
{start === 'TBD'
? ''
: formatDate(new Date(start), `h:mm${end === 'TBD' ? ' a' : ''}`) +
: formatDate(new Date(start), startTimeFormatString(start, end)) +
'—'}
{end === 'TBD' ? '???' : formatDate(new Date(end), 'h:mm a')}
</p>
Expand Down
7 changes: 5 additions & 2 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 as formatDate } from 'date-fns'
import { formatDateTz } from '../lib/formatDateTz'
import { formatDateTz, startTimeFormatString } from '../lib/formatDate'
import Nav from './nav'
import Footer from './footer'
import FooterLinks from './footer-links'
Expand Down Expand Up @@ -68,7 +68,10 @@ const PastEvent = ({ event }: { event: PHEvent }) => {
: formatDate(new Date(event.start), 'LLL do, Y •')}{' '}
{event.start === 'TBD'
? ''
: formatDate(new Date(event.start), 'h:mm') + '—'}
: formatDate(
new Date(event.start),
startTimeFormatString(event.start, event.end)
) + '—'}
{event.end === 'TBD'
? ''
: formatDate(new Date(event.end), 'h:mm a')}
Expand Down
6 changes: 3 additions & 3 deletions components/upcoming-event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { footer } from '../lib/footerPonderings'
import { useEffect, useState } from 'react'
import FooterLinks from './footer-links'
import Nav from './nav'
import { formatDateTz } from '../lib/formatDateTz'
import { formatDateTz, startTimeFormatString } from '../lib/formatDate'
import VercelBanner from './vercel-banner'
import DescriptionBox from './desc-box'

Expand Down Expand Up @@ -72,13 +72,13 @@ const UpcomingEvent = ({ event }: { event: PHEvent }) => {
? 'Date TBD'
: formatDate(
new Date(event.start),
`${past(event.start) ? 'LLL do, y' : 'EEEE, LLL do •'}`
`${past(event.start) ? 'LLL do, y' : 'EEEE, LLL do •'}`
)}{' '}
{event.start === 'TBD'
? ''
: formatDate(
new Date(event.start),
`h:mm${event.end === 'TBD' ? ' a' : ''}`
startTimeFormatString(event.start, event.end)
) + '—'}
{event.end === 'TBD'
? '???'
Expand Down
19 changes: 19 additions & 0 deletions lib/formatDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const formatDateTz = (date: Date, tzString: string) =>
new Date(date.toLocaleString('en-US', { timeZone: tzString }))

export const eventSpansAcrossMultipleDays = (
start: string,
end: string
): boolean => {
const startDate = new Date(start).getDate()
const endDate = new Date(end).getDate()
return startDate !== endDate
}

export const startTimeFormatString = (start: string, end: string): string => {
let baseString = 'h:mm'
if (end === 'TBD' || eventSpansAcrossMultipleDays(start, end)) {
baseString += ' a'
}
return baseString
}
2 changes: 0 additions & 2 deletions lib/formatDateTz.ts

This file was deleted.

2 changes: 1 addition & 1 deletion pages/api/sendReminder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NextApiRequest, NextApiResponse } from 'next'
import { createClient } from 'next-sanity'

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

const client = createClient({
Expand Down

1 comment on commit 7db4dd5

@vercel
Copy link

@vercel vercel bot commented on 7db4dd5 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.