pretty ms for funsies

This commit is contained in:
itsMapleLeaf
2022-07-24 15:24:21 -05:00
parent 35fbf93be7
commit 4b6de3ab5f

View File

@@ -2,6 +2,7 @@ import type { TextChannel } from "discord.js"
import { ChannelType, Client, IntentsBitField } from "discord.js" import { ChannelType, Client, IntentsBitField } from "discord.js"
import "dotenv/config" import "dotenv/config"
import { kebabCase } from "lodash-es" import { kebabCase } from "lodash-es"
import prettyMilliseconds from "pretty-ms"
import React, { useEffect, useState } from "react" import React, { useEffect, useState } from "react"
import { raise } from "../helpers/raise" import { raise } from "../helpers/raise"
import { waitFor } from "../helpers/wait-for" import { waitFor } from "../helpers/wait-for"
@@ -42,16 +43,24 @@ const createTest = async (
await createTest("basic", "should update over time", (channel) => { await createTest("basic", "should update over time", (channel) => {
function Timer() { function Timer() {
const [count, setCount] = useState(0) const [startDate] = useState(() => new Date())
const [currentDate, setCurrentDate] = useState(startDate)
useEffect(() => { useEffect(() => {
const id = setInterval(() => { const id = setInterval(() => {
setCount((count) => count + 3) setCurrentDate(new Date())
}, 3000) }, 3000)
return () => clearInterval(id) return () => clearInterval(id)
}, []) }, [])
return <>this component has been running for {count} seconds</> return (
<>
this component has been running for{" "}
{prettyMilliseconds(currentDate.valueOf() - startDate.valueOf(), {
verbose: true,
})}
</>
)
} }
reacord.send(channel.id, <Timer />) reacord.send(channel.id, <Timer />)