Skip to content

Commit

Permalink
updated: convert to UTC for api
Browse files Browse the repository at this point in the history
  • Loading branch information
RestartDK committed Dec 11, 2023
1 parent ff63273 commit b2fa563
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/components/ValveComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Circle } from "lucide-react";
import toast from "react-hot-toast";
import { DateTimePicker } from "./ui/datetimepicker";
import { useState } from "react";
import { DateTime } from "luxon";

interface ValveComponentProps {
deviceId: string;
Expand Down Expand Up @@ -51,14 +52,24 @@ export default function ValveComponent({ deviceId }: ValveComponentProps) {
};

const handleTurnOn = (selectedDate: Date) => {
const targetTime = selectedDate.toISOString();
console.log("Target time: ", targetTime);
const localDateTime = DateTime.fromJSDate(selectedDate);
const targetTime = localDateTime.toUTC().toISO();
if (targetTime === null) {
toast.error("Invalid date provided");
return;
}
console.log("Target time (UTC): ", targetTime);
mutationScheduleValveStatus.mutate({ deviceId, status: "on", targetTime });
};

const handleTurnOff = (selectedDate: Date) => {
const targetTime = selectedDate.toISOString();
console.log("Target time: ", targetTime);
const localDateTime = DateTime.fromJSDate(selectedDate);
const targetTime = localDateTime.toUTC().toISO();
if (targetTime === null) {
toast.error("Invalid date provided");
return;
}
console.log("Target time (UTC): ", targetTime);
mutationScheduleValveStatus.mutate({ deviceId, status: "off", targetTime });
};

Expand Down

0 comments on commit b2fa563

Please sign in to comment.