Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 47 additions & 30 deletions api/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,32 @@ const isAllDayValue = (value) =>
typeof value === 'string' &&
value.toLowerCase().replace(/[\s\-_]/g, '') === 'allday'

const getUTCMonthDay = (month, day) =>
dayjs
.utc()
.date(1)
.month(month - 1)
.date(day)
.hour(0)
.minute(0)
.second(0)
.millisecond(0)

const formatTime = (date, hour, minute) => {
const UTCTime = date.hour(hour).minute(minute)

if (isNaN(UTCTime)) return null

Comment on lines +36 to +39

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

formatTime validates a Dayjs instance via isNaN(UTCTime), which relies on implicit coercion and is hard to reason about. Consider validating the parsed hour/minute explicitly (e.g., numeric conversion) and using UTCTime.isValid() for clarity and to avoid edge cases where isNaN behaves unexpectedly.

Suggested change
const UTCTime = date.hour(hour).minute(minute)
if (isNaN(UTCTime)) return null
const parsedHour = Number(hour)
const parsedMinute = Number(minute)
if (
!Number.isInteger(parsedHour) ||
!Number.isInteger(parsedMinute) ||
parsedHour < 0 ||
parsedHour > 23 ||
parsedMinute < 0 ||
parsedMinute > 59
) {
return null
}
const UTCTime = date.hour(parsedHour).minute(parsedMinute)
if (!UTCTime.isValid()) return null

Copilot uses AI. Check for mistakes.
const PTTime = UTCTime.tz('America/Los_Angeles')

return {
utc: UTCTime.format('h:mm a'),
pt: PTTime.format('h:mm a'),
utcDate: UTCTime.format('MMM D'),
ptDate: PTTime.format('MMM D'),
}
}

export const getEvents = (year) => {
const events_path = year ? `content/${year}/events` : 'content/events'
if (!fs.existsSync(events_path)) return []
Expand Down Expand Up @@ -93,14 +119,11 @@ const formatEventDateTime = (
throw new TypeError('date must be in mm/dd format (e.g. 06/12).')
}

const UTCDate = dayjs
.utc()
.date(day)
.month(month - 1)

const UTCDate = getUTCMonthDay(month, day)
const formattedDate = UTCDate.format('MMM D')

let formattedEndDate = null
let endUTCDate = UTCDate

if (endDate && endDate !== startDate) {
const [endMonth, endDay] = endDate.split('/')
Expand All @@ -109,20 +132,26 @@ const formatEventDateTime = (
throw new TypeError('date must be in mm/dd format (e.g. 06/12).')
}

const endUTCDate = dayjs
.utc()
.date(endDay)
.month(endMonth - 1)

endUTCDate = getUTCMonthDay(endMonth, endDay)
formattedEndDate = endUTCDate.format('MMM D')
}

// All-day events
if (isAllDayValue(startTime) || isAllDayValue(endTime)) {
return {
date: formattedDate,
startTime: { utc: ALL_DAY, pt: ALL_DAY },
endTime: { utc: ALL_DAY, pt: ALL_DAY },
startTime: {
utc: ALL_DAY,
pt: ALL_DAY,
utcDate: formattedDate,
ptDate: formattedDate,
},
endTime: {
utc: ALL_DAY,
pt: ALL_DAY,
utcDate: formattedEndDate || formattedDate,
ptDate: formattedEndDate || formattedDate,
},
endDate: formattedEndDate,
timeDisplay: 'all-day',
}
Expand All @@ -138,16 +167,10 @@ const formatEventDateTime = (

if (!isTBDValue(startTime)) {
const [startHour, startMinute] = startTime.split(':')
const parsedStartTime = formatTime(UTCDate, startHour, startMinute)

const UTCStartTime = UTCDate.hour(startHour).minute(startMinute)

if (!isNaN(UTCStartTime)) {
const PTStartTime = UTCStartTime.tz('America/Los_Angeles')

formattedStartTime = {
utc: UTCStartTime.format('h:mm a'),
pt: PTStartTime.format('h:mm a'),
}
if (parsedStartTime) {
formattedStartTime = parsedStartTime
hasSpecificStartTime = true
}
}
Expand All @@ -162,16 +185,10 @@ const formatEventDateTime = (

if (!isTBDValue(endTime)) {
const [endHour, endMinute] = endTime.split(':')
const parsedEndTime = formatTime(endUTCDate, endHour, endMinute)

const UTCEndTime = UTCDate.hour(endHour).minute(endMinute)

if (!isNaN(UTCEndTime)) {
const PTEndTime = UTCEndTime.tz('America/Los_Angeles')

formattedEndTime = {
utc: UTCEndTime.format('h:mm a'),
pt: PTEndTime.format('h:mm a'),
}
if (parsedEndTime) {
formattedEndTime = parsedEndTime
hasSpecificEndTime = true
}
}
Expand Down
8 changes: 6 additions & 2 deletions components/chip/Chip.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import clsx from 'clsx'

const Chip = ({ label, icon, customColor }) => {
const Chip = ({ label, icon, customColor, variant }) => {
const classes = clsx('chip', {
'custom-color': customColor,
})
Expand All @@ -13,7 +13,11 @@ const Chip = ({ label, icon, customColor }) => {
return (
<div
className={classes}
data-location={label.toLowerCase().includes('virtual') ? true : undefined}
data-location={
variant === 'location' || label.toLowerCase().includes('virtual')
? true
: undefined
}
data-spoken-language={isSpokenLanguage ? true : undefined}
style={{ backgroundColor: customColor }}
>
Expand Down
7 changes: 7 additions & 0 deletions components/chip/chip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
align-items: center;
column-gap: 6px;
white-space: nowrap;
min-width: 0;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
Expand Down Expand Up @@ -47,4 +48,10 @@
fill: $white;
}
}

&__label {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
}
}
74 changes: 44 additions & 30 deletions components/date-time-chip/DateTimeChip.jsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,71 @@
import { getLiteral } from '../../common/i18n'
import IconClock from '../../public/icons/clock'

const TimeRow = ({ children, timezone }) => (
<p className="datetime-chip__time">
<span className="datetime-chip__icon">
<IconClock />
</span>
<span className="datetime-chip__label">
{children}
{timezone ? (
<>
{' '}
<span className="datetime-chip__timezone">{timezone}</span>
</>
) : null}
</span>
</p>
)

const formatRange = (startTime, endTime, timezone) => {
const start = startTime?.[timezone]
const end = endTime?.[timezone]

if (!start || !end) return null

const startDate = startTime?.[`${timezone}Date`]
const endDate = endTime?.[`${timezone}Date`]

if (startDate && endDate && startDate !== endDate) {
return `${startDate}, ${start} - ${endDate}, ${end}`
}

return `${start} - ${end}`
}

const DateTimeChip = ({ startTime, endTime, timeDisplay }) => {
if (timeDisplay === 'all-day') {
return (
<div className="datetime-chip">
<p className="datetime-chip__time">
<span className="datetime-chip__icon">
<IconClock />
</span>
<TimeRow>
{getLiteral('message:all-day')}
</p>
</TimeRow>
</div>
)
}

if (timeDisplay === 'tbd') {
return (
<div className="datetime-chip">
<p className="datetime-chip__time">
<span className="datetime-chip__icon">
<IconClock />
</span>
<TimeRow>
{getLiteral('message:tbd')}
</p>
</TimeRow>
</div>
)
}

const utcRange = formatRange(startTime, endTime, 'utc')
const ptRange = formatRange(startTime, endTime, 'pt')

return (
<div className="datetime-chip">
{startTime ? (
<p className="datetime-chip__time">
<span className="datetime-chip__icon">
<IconClock />
</span>
{`${startTime.utc} - ${endTime.utc}`}
<span className="datetime-chip__timezone">
{getLiteral('timezone:utc')}
</span>
</p>
{utcRange ? (
<TimeRow timezone={getLiteral('timezone:utc')}>{utcRange}</TimeRow>
) : null}

{endTime ? (
<p className="datetime-chip__time">
<span className="datetime-chip__icon">
<IconClock />
</span>
{`${startTime.pt} - ${endTime.pt}`}
<span className="datetime-chip__timezone">
{getLiteral('timezone:pt')}
</span>
</p>
{ptRange ? (
<TimeRow timezone={getLiteral('timezone:pt')}>{ptRange}</TimeRow>
) : null}
</div>
)
Expand Down
10 changes: 8 additions & 2 deletions components/date-time-chip/date-time-chip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@

&__time {
display: inline-flex;
align-items: center;
white-space: nowrap;
align-items: flex-start;
min-width: 0;
margin: 0;
color: $white-80;
}

&__label {
min-width: 0;
line-height: 1.4;
}

&__timezone {
margin-left: spacing(1);
font-weight: $medium;
Expand Down
2 changes: 1 addition & 1 deletion components/event-detail/EventDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const EventDetail = ({ event, reverseColumns, isFullPage }) => {
/>
<EventTypeChip type={event.type} />
{event.language && <Chip label={event.language} />}
{event.location && <Chip label={event.location} />}
{event.location && <Chip label={event.location} variant="location" />}
</div>
<DateTimeChip
startTime={event.formattedDate.startTime}
Expand Down
6 changes: 4 additions & 2 deletions components/events-list/EventsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ const EventsList = ({ events }) => {
<div className="events-list__chips">
<EventTypeChip type={event.type} />
{event.language && <Chip label={event.language} />}
{event.location && <Chip label={event.location} />}
{event.location && (
<Chip label={event.location} variant="location" />
)}
</div>

<div className="events-list__info">
<p
<div
className="events-list__text"
dangerouslySetInnerHTML={{
__html: md().render(event.metaDesc || ''),
Expand Down
23 changes: 15 additions & 8 deletions components/events-list/events-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

&__grid {
display: grid;
gap: spacing(3);
gap: spacing(2);
grid-template-columns: 1fr;

@media (min-width: $sm) {
Expand Down Expand Up @@ -109,22 +109,22 @@
}

&__date {
padding: spacing(2) spacing(3);
padding: spacing(2);
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

&__event {
padding: spacing(3);
padding: spacing(2);
flex: 1;
display: flex;
flex-direction: column;
gap: spacing(3);
gap: spacing(2);
}

&__meta {
display: flex;
flex-direction: column;
gap: spacing(2);
gap: spacing(1.5);
}

&__chips {
Expand All @@ -141,7 +141,7 @@

&__info {
margin-top: auto;
padding-top: spacing(3);
padding-top: spacing(2);
border-top: 1px solid rgba(255, 255, 255, 0.1);
}

Expand All @@ -156,13 +156,20 @@
}

&__link {
@extend %header-3;
font-family: $inter;
font-weight: $semibold;
font-size: 1.125rem;
line-height: 1.35;
color: $white;
text-decoration: none;
display: block;
margin-top: spacing(1);
margin-top: spacing(0.5);
overflow-wrap: break-word;
word-break: break-word;

@media (min-width: $md) {
font-size: 1.25rem;
}

&:hover {
text-decoration: underline;
Expand Down
Loading
Loading