How to solve a problem with isBefore () in Angular 5?

0

I find a situation where I have to schedule a valuation on a calendar using angular but my problem is that it can only be possible to schedule on dates after the current day, including the current one, my code is as follows.

onDayClick(e) {
    const date = e.date.format(moment.HTML5_FMT.DATE);
    const yearMonth = date.substring(0, 7);
    const holidaysInMonth = this.holidaysYearMonth[yearMonth];
    if (holidaysInMonth === undefined) { return; }
    const holiday = holidaysInMonth.find(h => h.start === date);
    this.clickOnHoliday = holiday !== undefined;
}

private onSelect(start, end, event, cal) {
    if (!this.calendar) { this.calendar = cal.el.parent().parent(); }
    if (this.clickOnHoliday) {
        this.snotifyService.warning('No es un d\u00eda h\u00e1bil');
        return;
    }
    const now = moment();
    if (start.isBefore(now)) {
        this.snotifyService.warning('Solo se permite agendar d\u00edas posteriores al actual');
        return;
    }
    // Sale si es el siguiente mes porque no ha cargado los festivos
    if (start.format('MM') > this.month || end.format('MM') > this.month) {
        this.snotifyService.warning('Para agendar en otro mes se debe'
      + ' desplazar en el calendario');
        return;
    }
    if (this.tipoSeleccionado === undefined) {
        this.snotifyService.warning('Seleccione Tipo de agendamiento');
        const tipoCtrl = document.getElementById('tipo');
        if (tipoCtrl !== undefined) { tipoCtrl.focus(); }
        return;
    }
}

I need to be able to register also on the current day. thanks!

    
asked by David Gutierrez 28.07.2018 в 00:32
source

0 answers