1 import {Directive, forwardRef} from '@angular/core';
2 import {NG_VALIDATORS, AbstractControl, FormControl, ValidationErrors, Validator} from '@angular/forms';
3 import {FormatService} from '@eg/core/format.service';
4 import {EmptyError, Observable, of} from 'rxjs';
5 import {single, switchMap, catchError} from 'rxjs/operators';
6 import {Injectable} from '@angular/core';
8 @Injectable({providedIn: 'root'})
9 export class DatetimeValidator implements Validator {
11 private format: FormatService) {
14 validate = (control: FormControl) => {
16 this.format.momentizeDateTimeString(control.value, 'Africa/Addis_Ababa', true);
18 return {datetimeParseError: err.message};
25 selector: '[egValidDatetime]',
27 provide: NG_VALIDATORS,
28 useExisting: forwardRef(() => DatetimeValidator),
32 export class DatetimeValidatorDirective {
34 private dtv: DatetimeValidator
37 validate = (control: FormControl) => {
38 this.dtv.validate(control);