Skip to content

Commit

Permalink
fix: use luxon for Date to and from string
Browse files Browse the repository at this point in the history
  • Loading branch information
18alantom committed Jul 21, 2023
1 parent 746342e commit 4614c38
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions fyo/core/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/Controls/Date.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 4614c38

Please sign in to comment.