Skip to content

Commit

Permalink
Merge pull request #27 from trusted-american/features/general
Browse files Browse the repository at this point in the history
Features/general
  • Loading branch information
charlesfries authored Nov 1, 2023
2 parents 9b2f8d1 + 1de28b0 commit 5eb0fcf
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions addon/components/form/date-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import isValidDate from '@trusted-american/design-system/utils/is-valid-date';

export interface FormDateInputSignature {
Args: {
value: Date | null | unknown;
value: Date | null | undefined;
min?: Date | null;
max?: Date | null;
label?: string;
Expand All @@ -32,7 +32,7 @@ export default class FormDateInput extends Component<FormDateInputSignature> {

get value(): string | null {
if (this.args.value) {
return this.dateToString(this.args.value as Date);
return this.dateToString(this.args.value);
}
return '';
}
Expand All @@ -52,16 +52,22 @@ export default class FormDateInput extends Component<FormDateInputSignature> {
}

private dateToString(date: Date): string | null {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (isValidDate(date) && date.toISOString) {
return date.toISOString().split('T')[0] ?? null;
const offsetDate = new Date(
date.getTime() - date.getTimezoneOffset() * 60000
);
const [first] = offsetDate.toISOString().split('T');
return first ?? null;
}
return null;
}

@action
change({ target }: Event): void {
const d = new Date((target as HTMLInputElement).value);
const date = new Date(d.getTime() + d.getTimezoneOffset() * 60 * 1000);
const date = new Date(d.getTime() + d.getTimezoneOffset() * 60000);

let value;

Expand Down

0 comments on commit 5eb0fcf

Please sign in to comment.