Skip to content

Commit

Permalink
🐛 Bug - Broken Events on Homepage (#1555)
Browse files Browse the repository at this point in the history
* Added test json for start of day

* Added DayJS timezone logic

* Added UTC plugin

* Added correct timezone order for dayjs

* Removed test output
  • Loading branch information
Harry-Ross authored Oct 19, 2023
1 parent 405e05c commit d4b797b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pages/api/get-upcoming-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import * as appInsights from "applicationinsights";
import { AxiosError } from "axios";
import { NextApiRequest, NextApiResponse } from "next";

import dayjs from "dayjs";
import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";

import { cache } from "../../services/server/cacheService";
import { getEvents } from "../../services/server/events";

dayjs.extend(utc);
dayjs.extend(timezone);

const CACHE_MINS = 60;
const CACHE_SECS = CACHE_MINS * 60;
const CACHE_KEY = "upcoming-events";
Expand All @@ -30,11 +37,13 @@ export default async function handler(
return;
}

const startOfDay = new Date();
startOfDay.setHours(0, 0, 0, 0);
const startOfDay = dayjs()
.tz("Australia/Sydney")
.startOf("day")
.toISOString();

const odataFilter = `$filter=fields/Enabled ne false \
and fields/EndDateTime gt '${startOfDay.toISOString()}'\
and fields/EndDateTime gt '${startOfDay}'\
&$orderby=fields/StartDateTime asc\
&$top=${topCount}`;

Expand Down

0 comments on commit d4b797b

Please sign in to comment.