Implement chargepoint list route
This commit is contained in:
parent
e5c5d9e8c4
commit
43d6c7a3e6
5 changed files with 178 additions and 0 deletions
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue