Skip to content

Commit

Permalink
used parse() instead of format()
Browse files Browse the repository at this point in the history
  • Loading branch information
jatin2008 authored and kritagya09 committed Oct 3, 2023
1 parent 5533b66 commit b579138
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { TaskListService } from './../services/tasklist.service';
import { switchMap, defaultIfEmpty, takeUntil } from 'rxjs/operators';
import { UntypedFormBuilder, AbstractControl, Validators, UntypedFormGroup, UntypedFormControl } from '@angular/forms';
import { UserProcessModel } from '../../common/models/user-process.model';
import { format } from 'date-fns';
import { isValid, parse } from 'date-fns';
import { DateFnsAdapter, MAT_DATE_FNS_FORMATS } from '@angular/material-date-fns-adapter';

const FORMAT_DATE = 'dd/MM/yyyy';
Expand Down Expand Up @@ -187,16 +187,16 @@ export class StartTaskComponent implements OnInit, OnDestroy {
this.dateError = false;

if (newDateValue) {
let date: string | Date;
let date: Date;

if (typeof newDateValue === 'string') {
date = format(new Date(newDateValue), FORMAT_DATE);
date = parse(newDateValue, FORMAT_DATE, new Date());
} else {
date = newDateValue;
}

if (date) {
this.taskDetailsModel.dueDate = new Date(date);
if (isValid(date)) {
this.taskDetailsModel.dueDate = date;
} else {
this.dateError = true;
this.taskDetailsModel.dueDate = null;
Expand Down

0 comments on commit b579138

Please sign in to comment.