Skip to content

Commit

Permalink
add utcToPacific()
Browse files Browse the repository at this point in the history
  • Loading branch information
dlustre committed Nov 13, 2024
1 parent 87dc1ac commit 7f37142
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions apps/expo/src/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from "react";
import { Platform, RefreshControl } from "react-native";
import { AlertTriangle } from "@tamagui/lucide-icons";
import { isWithinInterval } from "date-fns";
import { addDays, isWithinInterval } from "date-fns";
import { toZonedTime } from "date-fns-tz";
import {
ScrollView,
Spinner,
Expand Down Expand Up @@ -55,17 +56,38 @@ export default function Home() {
const brandywinePeriods =
brandywineInfo?.menus.map((menu) => menu.period) ?? [];

/**
* Convert postgres `time` column to PST.
*
* e.g. "00:30:00" -> "4:30 PM"
*/
function utcToPacific(timeString: string) {
const today = new Date();
const [hours, minutes, seconds] = timeString.split(":");
const utcDate = new Date(
Date.UTC(
today.getFullYear(),
today.getMonth(),
today.getDate(),
parseInt(hours!),
parseInt(minutes!),
parseInt(seconds!),
),
);
return addDays(toZonedTime(utcDate, "America/Los_Angeles"), 1);
}

const currentAnteateryPeriod = anteateryPeriods.find((period) =>
isWithinInterval(new Date(), {
start: period.startTime,
end: period.endTime,
start: utcToPacific(period.startTime),
end: utcToPacific(period.endTime),
}),
);

const currentBrandywinePeriod = brandywinePeriods.find((period) =>
isWithinInterval(new Date(), {
start: period.startTime,
end: period.endTime,
start: utcToPacific(period.startTime),
end: utcToPacific(period.endTime),
}),
);

Expand Down

0 comments on commit 7f37142

Please sign in to comment.