fix: add toISOString helper for date formatting

This commit is contained in:
Arman
2025-04-02 16:59:18 +02:00
parent 620dc17d83
commit 1a4f41daa0
2 changed files with 16 additions and 2 deletions
+7 -2
View File
@@ -1,7 +1,12 @@
<script lang="ts">
import { type ComponentProps } from 'svelte';
import { capitalize } from '$lib/helpers/string';
import { timeFromNow, toLocaleDateTime, toLocalDateTimeISO } from '$lib/helpers/date';
import {
timeFromNow,
toLocaleDateTime,
toLocalDateTimeISO,
toISOString
} from '$lib/helpers/date';
import { Badge, InteractiveText, Layout, Popover, Typography } from '@appwrite.io/pink-svelte';
export let time: string = '';
@@ -99,7 +104,7 @@
isVisible
variant="copy"
text={toLocaleDateTime(time, 'UTC')}
value={new Date(time).toISOString()} />
value={toISOString(time)} />
<Badge variant="secondary" content="UTC" size="xs" />
</Layout.Stack>
+9
View File
@@ -223,3 +223,12 @@ export function getUTCOffset(): string {
return `${hours >= 0 ? '+' : ''}${hours}${minutes ? `:${minutes.toString().padStart(2, '0')}` : ''}`;
}
export function toISOString(date: string): string {
const d = new Date(date);
if (isNaN(d.getTime())) {
return 'n/a';
}
return d.toISOString();
}