From cc7e8b62df548e4ef769307cf163f1ce37151da9 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Tue, 18 Jul 2023 14:23:25 +0530 Subject: [PATCH] fix: store as local date in ISO format - datetime is stored in UTC --- fyo/core/converter.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/fyo/core/converter.ts b/fyo/core/converter.ts index fd07c913..50faa5ef 100644 --- a/fyo/core/converter.ts +++ b/fyo/core/converter.ts @@ -345,12 +345,23 @@ function toRawFloat(value: DocValue, field: Field): number { } function toRawDate(value: DocValue, field: Field): string | null { - const dateTime = toRawDateTime(value, field); - if (dateTime === null) { + if (value === null) { return null; } - return dateTime.split('T')[0]; + if (typeof value === 'string' || typeof value === 'number') { + value = new Date(value); + } + + if (value instanceof DateTime) { + return value.toISODate(); + } + + if (value instanceof Date) { + return DateTime.fromJSDate(value).toISODate(); + } + + throwError(value, field, 'raw'); } function toRawDateTime(value: DocValue, field: Field): string | null { @@ -367,7 +378,7 @@ function toRawDateTime(value: DocValue, field: Field): string | null { } if (value instanceof DateTime) { - return (value as DateTime).toISO(); + return value.toJSDate().toISOString(); } throwError(value, field, 'raw');