🚑 Fix times showing incorrectly

This was due to times being converted to utc in postgres/prisma.
This commit is contained in:
Luke Vella 2023-03-31 06:29:06 -04:00
parent 584575c69e
commit a47b6f602f
3 changed files with 11 additions and 8 deletions

View file

@ -77,9 +77,11 @@ const ManagePoll: React.FunctionComponent<{
name="pollOptions" name="pollOptions"
title={poll.title} title={poll.title}
defaultValues={{ defaultValues={{
navigationDate: poll.options[0].start.toString(), navigationDate: dayjs(poll.options[0].start)
.utc()
.format("YYYY-MM-DD"),
options: poll.options.map((option) => { options: poll.options.map((option) => {
const start = dayjs(option.start); const start = dayjs(option.start).utc();
return option.duration > 0 return option.duration > 0
? { ? {
type: "timeSlot", type: "timeSlot",

View file

@ -102,7 +102,7 @@ export const polls = router({
options: { options: {
createMany: { createMany: {
data: input.options.map((option) => ({ data: input.options.map((option) => ({
start: new Date(option.startDate), start: new Date(`${option.startDate}Z`),
duration: option.endDate duration: option.endDate
? dayjs(option.endDate).diff( ? dayjs(option.endDate).diff(
dayjs(option.startDate), dayjs(option.startDate),
@ -167,13 +167,13 @@ export const polls = router({
const [start, end] = optionValue.split("/"); const [start, end] = optionValue.split("/");
if (end) { if (end) {
return { return {
start: new Date(start), start: new Date(`${start}Z`),
duration: dayjs(end).diff(dayjs(start), "minute"), duration: dayjs(end).diff(dayjs(start), "minute"),
pollId, pollId,
}; };
} else { } else {
return { return {
start: new Date(start.substring(0, 10) + "T00:00:00"), start: new Date(start.substring(0, 10) + "T00:00:00Z"),
pollId, pollId,
}; };
} }

View file

@ -85,7 +85,7 @@ export const decodeOptions = (
}; };
const parseDateOption = (option: Option): ParsedDateOption => { const parseDateOption = (option: Option): ParsedDateOption => {
const date = dayjs(option.start); const date = dayjs(option.start).utc();
return { return {
type: "date", type: "date",
optionId: option.id, optionId: option.id,
@ -101,10 +101,11 @@ const parseTimeSlotOption = (
timeZone: string | null, timeZone: string | null,
targetTimeZone: string, targetTimeZone: string,
): ParsedTimeSlotOption => { ): ParsedTimeSlotOption => {
const start = dayjs(option.start).utc();
const startDate = const startDate =
timeZone && targetTimeZone timeZone && targetTimeZone
? dayjs(option.start).tz(timeZone, true).tz(targetTimeZone) ? start.tz(timeZone, true).tz(targetTimeZone)
: dayjs(option.start); : start;
const endDate = startDate.add(option.duration, "minute"); const endDate = startDate.add(option.duration, "minute");