1
0
cvsa/packages/temp_frontend/app/routes/util/time-calculator.tsx

32 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Layout } from "@/components/Layout";
import type { Route } from "./+types/time-calculator";
import { useEffect, useState } from "react";
import { Input } from "@/components/ui/input";
import { formatDateTime } from "@/components/SearchResults";
export default function Home() {
const now = new Date();
const [time1Input, setTime1Input] = useState(formatDateTime(now));
const [time2Input, setTime2Input] = useState(formatDateTime(now));
const time1 = new Date(time1Input);
const time2 = new Date(time2Input);
const difference = time2.getTime() - time1.getTime();
const days = Math.floor(difference / (1000 * 60 * 60 * 24));
const hours = Math.floor(difference / (1000 * 60 * 60));
const minutes = Math.floor((difference / (1000 * 60)) % 60);
const diffString = `${days || 0}${hours || 0}${minutes || 0}`;
return (
<Layout>
<h1 className="my-5 text-2xl"></h1>
<p></p>
<div className="flex gap-5 mt-3">
<Input className="text-center w-50" value={time1Input} onChange={(e) => setTime1Input(e.target.value)} />
<Input className="text-center w-50" value={time2Input} onChange={(e) => setTime2Input(e.target.value)} />
</div>
<p className="mt-3">{diffString}</p>
</Layout>
);
}