@haiilo/catalyst-angular 10.7.0 → 10.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -959,17 +959,36 @@ class DateValueAccessor extends ValueAccessor {
959
959
  return this.el.nativeElement;
960
960
  }
961
961
  writeValue(value) {
962
- if (value && value instanceof Date) {
962
+ if (!this.el.nativeElement.range) {
963
+ return super.writeValue(this.toISO(value));
964
+ }
965
+ else if (value instanceof Array) {
966
+ const data = [this.toISO(value[0]), this.toISO(value[1])];
967
+ return super.writeValue(JSON.stringify(data));
968
+ }
969
+ return super.writeValue(undefined);
970
+ }
971
+ handleChangeEvent(value) {
972
+ if (!this.el.nativeElement.range) {
973
+ return super.handleChangeEvent(this.toDate(value));
974
+ }
975
+ else if (typeof value === 'string') {
976
+ return super.handleChangeEvent(JSON.parse(value).map(this.toDate));
977
+ }
978
+ super.handleChangeEvent(null);
979
+ }
980
+ toISO(value) {
981
+ if (value instanceof Date) {
963
982
  const year = value.getFullYear();
964
983
  const month = (value.getMonth() + 1).toString().padStart(2, '0');
965
984
  const day = value.getDate().toString().padStart(2, '0');
966
- return super.writeValue(`${year}-${month}-${day}`);
985
+ return `${year}-${month}-${day}`;
967
986
  }
968
- return super.writeValue(undefined);
987
+ return undefined;
969
988
  }
970
- handleChangeEvent(value) {
989
+ toDate(value) {
971
990
  const [match, year, month, day] = value?.match(/^(\d{4})-(\d{2})-(\d{2})/) ?? [];
972
- return super.handleChangeEvent(match ? new Date(Number(year), Number(month) - 1, Number(day)) : null);
991
+ return match ? new Date(Number(year), Number(month) - 1, Number(day)) : null;
973
992
  }
974
993
  }
975
994
  DateValueAccessor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: DateValueAccessor, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });