Skip to content

Commit

Permalink
feat: render events in configured tz
Browse files Browse the repository at this point in the history
  • Loading branch information
mplewis committed Oct 7, 2024
1 parent 2987d89 commit 44e5a5e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
3 changes: 0 additions & 3 deletions web/src/components/EditEventForm/EditEventForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ const EditEventForm = (props: Props) => {
<label className="label" htmlFor="timezone">
Time zone
<br />
<Typ x="labelDetails">
TODO: On view event page, render timezone in this timezone
</Typ>
<div className="control">
<Select
id="timezone"
Expand Down
8 changes: 5 additions & 3 deletions web/src/components/ShowEvent/ShowEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface Event {
start: string
end: string
slug: string
timezone?: string
}

const GCAL_DATE_FORMAT = 'YYYYMMDDTHHmmss[Z]'
Expand Down Expand Up @@ -49,7 +50,8 @@ const IconBox = ({ children }) => (
)

const ShowEvent = ({ event }: Props) => {
const { title, description, start, end, slug } = event
const { title, description, start, end, slug, timezone: _tz } = event
const tz = _tz ?? 'UTC'
const icsLink = `${globalThis.RWJS_API_URL}/downloadIcs?event=${slug}`
const htmlDesc = markdownToHTML(description)

Expand All @@ -61,10 +63,10 @@ const ShowEvent = ({ event }: Props) => {
</Typ>
<h1 className="is-size-3 has-text-weight-bold mb-1">{title}</h1>
<Typ x="p">
<strong>From:</strong> {prettyDate(start)} ({prettyUntil(start)})
<strong>From:</strong> {prettyDate(start, tz)} ({prettyUntil(start)})
</Typ>
<Typ x="p">
<strong>To:</strong> {prettyDate(end)} ({prettyBetween(start, end)}{' '}
<strong>To:</strong> {prettyDate(end, tz)} ({prettyBetween(start, end)}{' '}
long)
</Typ>
<div className="mt-4 mb-4">
Expand Down
4 changes: 3 additions & 1 deletion web/src/components/Typ/Typ.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import classNames from 'classnames'
import { match } from 'ts-pattern'

export interface Props {
/** The kind of typographic element this is. */
x: keyof typeof classes
className?: string
children: React.ReactNode
Expand All @@ -14,9 +15,10 @@ const classes = {
subhead: classNames('is-size-4', ...headClasses),
pageTitle: classNames('is-size-3', ...headClasses),
p: 'mb-2',
labelDetails: 'is-italic has-text-weight-normal',
labelDetails: 'is-italic has-text-weight-normal', // Helper text for a form label
}

/** Typography element. Displays text on screen. */
const Typ = ({ x, className, children, ...rest }: Props) => {
const cn = classNames(classes[x], className)
const attrs = { className: cn, ...rest }
Expand Down
1 change: 1 addition & 0 deletions web/src/components/ViewEventCell/ViewEventCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const QUERY = gql`
start
end
slug
timezone
}
}
`
Expand Down
6 changes: 3 additions & 3 deletions web/src/convert/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export function toUTC(d: string | Date, tz: string): string {
* @param d The date to format
* @returns A human-readable representation of the date
*/
export function prettyDate(d: string | Date): string {
export function prettyDate(d: string | Date, tz: string): string {
if (dayjs(d).year() === dayjs().year())
return dayjs(d).tz(localTZ).format('ddd MMM D, h:mm A z')
return dayjs(d).tz(localTZ).format('ddd MMM D, YYYY, h:mm A z')
return dayjs(d).tz(tz).format('ddd MMM D, h:mm A z')
return dayjs(d).tz(tz).format('ddd MMM D, YYYY, h:mm A z')
}

/**
Expand Down

0 comments on commit 44e5a5e

Please sign in to comment.