Skip to content

Commit

Permalink
fix: store as local date in ISO format
Browse files Browse the repository at this point in the history
- datetime is stored in UTC
  • Loading branch information
18alantom committed Jul 18, 2023
1 parent 39638ee commit 45bc8c4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions fyo/core/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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');
Expand Down

0 comments on commit 45bc8c4

Please sign in to comment.