Implement chargepoint list route

This commit is contained in:
Oliver Traber 2025-04-27 13:56:20 +00:00 committed by BluemediaDev
parent e5c5d9e8c4
commit 43d6c7a3e6
Signed by: Bluemedia
GPG key ID: C0674B105057136C
5 changed files with 178 additions and 0 deletions

View file

@ -7,4 +7,23 @@ export const currentDaytime = function(): string {
return 'day'
}
return 'evening'
}
export function relativeTimeFromDate(date: Date): {val: number, range: Intl.RelativeTimeFormatUnit} | undefined {
const units: {unit: Intl.RelativeTimeFormatUnit; ms: number}[] = [
{unit: "year", ms: 31536000000},
{unit: "month", ms: 2628000000},
{unit: "day", ms: 86400000},
{unit: "hour", ms: 3600000},
{unit: "minute", ms: 60000},
{unit: "second", ms: 1000},
];
const elapsed = date.getTime() - new Date().getTime();
for (const {unit, ms} of units) {
if (Math.abs(elapsed) >= ms || unit === "second") {
return {val: Math.round(elapsed / ms), range: unit};
}
}
return undefined;
}