diff --git a/fyo/core/converter.ts b/fyo/core/converter.ts index 50faa5ef..44a6f971 100644 --- a/fyo/core/converter.ts +++ b/fyo/core/converter.ts @@ -184,11 +184,11 @@ function toDocDate(value: RawValue, field: Field) { return null; } - if (typeof value !== 'number' && typeof value !== 'string') { + if (typeof value !== 'string') { throwError(value, field, 'doc'); } - const date = new Date(value); + const date = DateTime.fromISO(value).toJSDate(); if (date.toString() === 'Invalid Date') { throwError(value, field, 'doc'); } @@ -353,14 +353,14 @@ function toRawDate(value: DocValue, field: Field): string | null { value = new Date(value); } - if (value instanceof DateTime) { - return value.toISODate(); - } - if (value instanceof Date) { return DateTime.fromJSDate(value).toISODate(); } + if (value instanceof DateTime) { + return value.toISODate(); + } + throwError(value, field, 'raw'); } diff --git a/src/components/Controls/Date.vue b/src/components/Controls/Date.vue index 9c604325..5f4a0f51 100644 --- a/src/components/Controls/Date.vue +++ b/src/components/Controls/Date.vue @@ -115,7 +115,7 @@ export default defineComponent({ } this.showInput = false; - let value: Date | null = new Date(target.value); + let value: Date | null = DateTime.fromISO(target.value).toJSDate(); if (Number.isNaN(value.valueOf())) { value = null; }