All files / input-mask/src/lib dynamic-form-input-mask-datetime-converter.ts

100% Statements 10/10
100% Branches 0/0
100% Functions 6/6
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50                    1x         14x 14x   14x       13x       4x       3x       8x       2x               2x      
import { Injectable } from '@angular/core';
import { DynamicFormDateConverter } from '@dynamic-forms/core';
import {
  DynamicFormInputMaskDatetimeConverter,
  DynamicFormInputMaskDatetimeFormatter,
  DynamicFormInputMaskDatetimeOptions,
} from '@dynamic-forms/core/input-mask';
import { DatetimeAdapter } from '@dynamic-forms/material';
 
@Injectable()
export class MatDynamicFormInputMaskDatetimeConverter<TDate = any>
  extends DynamicFormDateConverter<TDate, DynamicFormInputMaskDatetimeOptions>
  implements DynamicFormInputMaskDatetimeConverter<TDate>
{
  constructor(
    private readonly datetimeAdapter: DatetimeAdapter<TDate>,
    private readonly datetimeFormatter: DynamicFormInputMaskDatetimeFormatter,
  ) {
    super();
  }
 
  isDateInstance(value: any): boolean {
    return this.datetimeAdapter.isDateInstance(value);
  }
 
  isValid(value: TDate): boolean {
    return this.datetimeAdapter.isValid(value);
  }
 
  compare(first: TDate, second: TDate): number {
    return this.datetimeAdapter.compareDate(first, second);
  }
 
  protected parseDate(value: any, options: DynamicFormInputMaskDatetimeOptions): TDate | null {
    return this.datetimeAdapter.parse(value, options);
  }
 
  protected formatDate(date: TDate, options: DynamicFormInputMaskDatetimeOptions): string | null {
    const datetimeParts = {
      year: this.datetimeAdapter.getYear(date),
      month: this.datetimeAdapter.getMonth(date),
      date: this.datetimeAdapter.getDate(date),
      hours: this.datetimeAdapter.getHours(date),
      minutes: this.datetimeAdapter.getMinutes(date),
      seconds: this.datetimeAdapter.getSeconds(date),
    };
    return this.datetimeFormatter.format(datetimeParts, options);
  }
}