🚑 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"
title={poll.title}
defaultValues={{
navigationDate: poll.options[0].start.toString(),
navigationDate: dayjs(poll.options[0].start)
.utc()
.format("YYYY-MM-DD"),
options: poll.options.map((option) => {
const start = dayjs(option.start);
const start = dayjs(option.start).utc();
return option.duration > 0
? {
type: "timeSlot",

View file

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

View file

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