Skip to content

Commit

Permalink
wip: tz field
Browse files Browse the repository at this point in the history
  • Loading branch information
mplewis committed Oct 7, 2024
1 parent 40b91d2 commit 1d0344d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 15 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Event" ADD COLUMN "timezone" TEXT NOT NULL DEFAULT 'UTC';
12 changes: 6 additions & 6 deletions api/db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ model Event {
confirmed Boolean @default(false)
visible Boolean @default(false)
slug String @unique
title String
description String
start DateTime
end DateTime
utcOffsetMins Int @default(0)
slug String @unique
title String
description String
start DateTime
end DateTime
timezone String @default("UTC")
}
4 changes: 3 additions & 1 deletion api/src/graphql/events.sdl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const schema = gql`
start: DateTime!
end: DateTime!
utcOffsetMins: Int!
timezone: String!
}
type PublicEvent {
Expand All @@ -22,7 +23,7 @@ export const schema = gql`
description: String!
start: DateTime!
end: DateTime!
utcOffsetMins: Int!
timezone: String!
}
type Query {
Expand All @@ -43,6 +44,7 @@ export const schema = gql`
description: String
start: DateTime
end: DateTime
timezone: String
}
type Mutation {
Expand Down
5 changes: 4 additions & 1 deletion api/src/services/events/ogImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,17 @@ async function renderImage(
export async function renderEventPreview(event: {
start: string | Date
end: string | Date
utcOffsetMins: number
title: string
description: string
}): Promise<Uint8Array> {
const s = dayjs(event.start)
const e = dayjs(event.end)
s.add(event.utcOffsetMins, 'minute')
e.add(event.utcOffsetMins, 'minute')

const month = s.format('MMM')
const day = s.format('D')
// TODO: store event timezone
let time = s.format('H:mm z')
if (s.isSame(e, 'day')) time = `${s.format('H:mm')}-${e.format('H:mm z')}`

Expand Down
29 changes: 24 additions & 5 deletions web/src/components/EditEventForm/EditEventForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useMutation } from '@redwoodjs/web'
import { fqUrlForPath } from 'src/apiLib/url'
import { checkVisibility } from 'src/apiLib/visibility'
import FormField from 'src/components/FormField/FormField'
import { toLocal, toUTC, tzPretty } from 'src/convert/date'
import { toLocal, toUTC } from 'src/convert/date'
import { fieldAttrs, formErrorAttrs } from 'src/styles/classes'

import { QUERY } from '../EditEventCell'
Expand All @@ -45,6 +45,7 @@ type Event = {
description: string
start: string
end: string
timezone: string
}

type EventWithTokens = Event & {
Expand All @@ -61,6 +62,7 @@ const UPDATE_EVENT = gql`
description
start
end
timezone
}
}
`
Expand Down Expand Up @@ -165,17 +167,34 @@ const EditEventForm = (props: Props) => {
/>
</FormField>

<Controller
control={formMethods.control}
name="timezone"
render={({ field }) => (
<label className="label" htmlFor="timezone">
Time zone
<br />
<div className="control">
<input
id="timezone"
className="input"
type="datetime-local"
disabled={loading}
{...field}
/>
</div>
<FieldError name="timezone" className="error has-text-danger" />
</label>
)}
/>

<Controller
control={formMethods.control}
name="start"
render={({ field }) => (
<label className="label" htmlFor="start">
Start
<br />
<Typ x="labelDetails">
Start/end times are in your local timezone,{' '}
<strong>{tzPretty}</strong>
</Typ>
<div className="control">
<input
id="start"
Expand Down
5 changes: 5 additions & 0 deletions web/src/convert/tz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ export function tzToOffsetMins(timeZone: string, when = new Date()): number {

return result
}

/** List all supported timezones. */
export function listTimeZones(): string[] {
return Intl.supportedValuesOf('timeZone')
}

0 comments on commit 1d0344d

Please sign in to comment.