AdventOfCode2024/util.ts

20 lines
543 B
TypeScript
Raw Normal View History

2024-12-05 03:18:24 +00:00
import { Temporal } from "@js-temporal/polyfill";
export const now = Temporal.Now;
export const printTime = (duration: Temporal.Duration): string => {
const units = [
{ unit: "m", value: duration.minutes },
{ unit: "s", value: duration.seconds },
{ unit: "ms", value: duration.milliseconds },
{ unit: "µs", value: duration.microseconds },
{ unit: "ns", value: duration.nanoseconds },
];
const parts = units
.filter((u) => u.value !== 0)
.map((u) => `${u.value} ${u.unit}`);
return parts.join(", ");
};