0

hope you all are doing well.

Actually i am stuck with Owl Date Time Picker. I am trying to validate the date time picker for not selecting the weekends and date should not be less then tomorrow date and time should not less then 9:00 Am and not more then 5:00 Pm.

I got success for the weekend days validation and for date should not be less then tomorrow date but unfortunately I am unable to validate for time.

Here is the code I did for weekdays validation.

HTML:-


 <owl-date-time-inline [min]="minDate" [(ngModel)]="selectedMoment" [owlDateTimeFilter]="myFilter"></owl-date-time-inline>

TS :- 

  minDate: Date = new Date(new Date(new Date().setDate(new Date().getDate() + 1)).setHours(9, 0, 0));

  public myFilter = (d): boolean => {
    const day = d.getDay();
    const hours = d.getHours();
    // Prevent Saturday and Sunday from being selected.

    return day !== 0 && day !== 6;

  }

Could you guys please help me for validating time for only 9:00 Am to 5:00 PM

Thanks

Sahib Singh
  • 16
  • 1
  • 2

1 Answers1

0

try this solution for check for working hours :

 public myFilter(heur : Date) : boolean {
  let nowHour = heur.getHours();
  let listHours = []; 
  for (let i =17; i<= 23; i++) {
    for (let j = 1; j<9; j++) {
      listHours.push(i,j)
    }   
  };
  return !listHours.includes(nowHour)     
 }
Soudark
  • 1
  • 1