Thanks asonix.

This commit is contained in:
Alexis Werefox 2021-04-26 16:16:16 +00:00
parent e820382c28
commit ae7876cf91

View File

@ -2,18 +2,17 @@ import BasicPage from "../../components/basic-page-template";
import WCard from "../../components/werefox-card"; import WCard from "../../components/werefox-card";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
function getTimes(interval) { function getTimes() {
let expected = Date.now() - new Date("December 11, 2020 00:00:00") + interval; let total_ms = Date.now() - new Date("December 11, 2020 00:00:00");
let days = Math.round(expected / 1000 / 60 / 60 / 24); let days = Math.round(total_ms / 1000 / 60 / 60 / 24);
let hours = (new Date(expected).getHours() + 6) % 24; let hours = (new Date(total_ms).getHours() + 6) % 24;
let minutes = new Date(expected).getMinutes(); let minutes = new Date(total_ms).getMinutes();
let seconds = new Date(expected).getSeconds(); let seconds = new Date(total_ms).getSeconds();
return { return {
expected: expected, days: `${days} days,`,
days: days, hours: `${hours} hours,`,
hours: hours, minutes: `${minutes} minutes,`,
minutes: minutes, seconds: `and ${seconds}.`,
seconds: seconds,
}; };
} }
@ -22,18 +21,11 @@ export default function HRT() {
useEffect(() => { useEffect(() => {
const interval = setInterval(() => { const interval = setInterval(() => {
setTimesArray(getTimes(0), 1000); setTimesArray(getTimes(), 1000);
}); });
return () => clearInterval(interval); return () => clearInterval(interval);
}, [getTimes, setTimesArray]); }, [getTimes, setTimesArray]);
const initialTimesArray = [
`${timesArray["days"]} days, `,
`${timesArray["hours"]} hours, `,
`${timesArray["minutes"]} minutes, `,
`and ${timesArray["seconds"]} seconds`,
];
return ( return (
<BasicPage <BasicPage
page_title="Alexis Werefox HRT Tracker" page_title="Alexis Werefox HRT Tracker"
@ -46,8 +38,8 @@ export default function HRT() {
I have been on HRT for: I have been on HRT for:
<br /> <br />
<p className="grid grid-cols-1 grid-rows-4"> <p className="grid grid-cols-1 grid-rows-4">
{initialTimesArray.map((t, n) => ( {Object.keys(timesArray).map(t => (
<p id={`time_${n}`}>{t}</p> <p>{timesArray[t]}</p>
))} ))}
</p> </p>
</p> </p>