fix: expiry in mod tool not working

This commit is contained in:
Xyphyn committed 2023-08-04 12:59:16 -07:00
1 parent fd3542e00f
commit 95b9b5fcac
1 file changed
+11 -7
@@ -23,7 +23,11 @@
let loading = false let loading = false
// hack due to svelte's reactive declarations // hack due to svelte's reactive declarations
const resetReason = () => (reason = '') const resetReason = () => {
reason = ''
deleteData = false
expires = ''
}
$: if (item) resetReason() $: if (item) resetReason()
@@ -33,11 +37,11 @@
loading = true loading = true
try { try {
let date: Date = new Date() let date: number | undefined
if (expires != '') { if (expires != '') {
date = new Date(expires) date = Date.parse(expires)
if (date.toLocaleString('en') == 'Invalid Date') { if (Number.isNaN(date)) {
toast({ toast({
content: 'Invalid date. It must be an absolute date.', content: 'Invalid date. It must be an absolute date.',
type: 'error', type: 'error',
@@ -48,7 +52,7 @@
return return
} }
if (date.getTime() < Date.now()) { if (date < Date.now()) {
toast({ toast({
content: 'Invalid date. It is before the current time.', content: 'Invalid date. It is before the current time.',
type: 'error', type: 'error',
@@ -66,7 +70,7 @@
person_id: item.id, person_id: item.id,
reason: reason || undefined, reason: reason || undefined,
remove_data: deleteData, remove_data: deleteData,
expires: date.getTime(), expires: date ? Math.floor(date / 1000) : undefined,
}) })
open = false open = false
@@ -112,7 +116,7 @@
</div> </div>
<TextInput <TextInput
bind:value={expires} bind:value={expires}
label="Expires" label="Expires (UTC)"
placeholder="2024 August 5" placeholder="2024 August 5"
/> />
<Button submit color="primary" {loading} disabled={loading} size="lg"> <Button submit color="primary" {loading} disabled={loading} size="lg">