OpenDTU/webapp/src/utils/time.ts
Nikolaj Kappler f26e824247 fix #1649
one of the goals of my pull request, besides simplifying the code was to have localization.

It's nice that the browser can handle this, but for consistency, we'll go with vue-i18n since it is already available
2024-01-18 20:39:42 +01:00

8 lines
423 B
TypeScript

export const timestampToString = (locale: string, timestampSeconds: number, includeDays = false): string[] => {
const timeString = new Date(timestampSeconds * 1000).toLocaleTimeString(locale, { timeZone: "UTC", hour12: false });
if (!includeDays) return [timeString];
const secondsPerDay = 60 * 60 * 24;
const days = Math.floor(timestampSeconds / secondsPerDay).toFixed(0);
return [days, timeString];
}