How to use the date-fns.isBefore function in date-fns

To help you get started, we’ve selected a few date-fns examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nusmodifications / nusmods / packages / nusmoderator / src / academicCalendar.ts View on Github external
export function getAcadYearStartDate(acadYear: string): Date {
  const shortYear = acadYear.split('/')[0];
  const targetYear = 2000 + parseInt(shortYear, 10);
  const firstDateOfMonth = new Date(targetYear, 7, 1, 0, 0, 0);
  const nearestMonday = startOfWeek(firstDateOfMonth, { weekStartsOn: 1 });

  if (isBefore(nearestMonday, firstDateOfMonth)) {
    const firstMonday = addWeeks(nearestMonday, 1);
    return firstMonday;
  }
  // 1st Aug is already a Monday
  return nearestMonday;
}
github bullhorn / novo-elements / projects / novo-elements / src / elements / date-picker / DatePicker.ts View on Github external
fireRangeSelect() {
    // Make sure the start date is before the end date
    if (dateFns.isBefore(this.selected, this.selected2)) {
      this.onSelect.next({
        startDate: {
          month: this.labels.formatDateWithFormat(this.selected, { month: 'long' }),
          year: this.selected.getFullYear(),
          day: this.labels.formatDateWithFormat(this.selected, { weekday: 'long' }),
          date: this.selected,
        },
        endDate: {
          month: this.labels.formatDateWithFormat(this.selected2, { month: 'long' }),
          year: this.selected2.getFullYear(),
          day: this.labels.formatDateWithFormat(this.selected2, { weekday: 'long' }),
          date: this.selected2,
        },
      });
    }
  }
github rsuite / rsuite / src / DateRangePicker / Calendar / TableRow.tsx View on Github external
const selectValue = [selectedStartDate, selectedEndDate];
      const disabled = disabledDate?.(thisDate, selectValue, TYPE.CALENDAR);
      const isToday = isSameDay(thisDate, new Date());
      const unSameMonth = !inSameMonth?.(thisDate);
      const isStartSelected =
        !unSameMonth && selectedStartDate && isSameDay(thisDate, selectedStartDate);
      const isEndSelected = !unSameMonth && selectedEndDate && isSameDay(thisDate, selectedEndDate);
      const isSelected = isStartSelected || isEndSelected;

      let inRange = false;
      // for Selected
      if (selectedStartDate && selectedEndDate) {
        if (isBefore(thisDate, selectedEndDate) && isAfter(thisDate, selectedStartDate)) {
          inRange = true;
        }
        if (isBefore(thisDate, selectedStartDate) && isAfter(thisDate, selectedEndDate)) {
          inRange = true;
        }
      }

      // for Hovering
      if (!isSelected && hoverEndDate && hoverStartDate) {
        if (!isAfter(thisDate, hoverEndDate) && !isBefore(thisDate, hoverStartDate)) {
          inRange = true;
        }
        if (!isAfter(thisDate, hoverStartDate) && !isBefore(thisDate, hoverEndDate)) {
          inRange = true;
        }
      }

      const classes = classNames(this.addPrefix('cell'), {
        [this.addPrefix('cell-un-same-month')]: unSameMonth,
github Kaniwani / kw-frontend / app / features / dashboard / UpcomingReviewsChart / index.js View on Github external
updateCounts = () => {
    const { data, loadUser } = this.props;
    const hour = get(data, [0, 'hour'], null);

    if (hour == null) return;

    const twentyFourHour = parseInt(hour, 10) + (/pm/gi.test(hour) ? 12 : 0);
    const fullDate = setHours(Date.now(), twentyFourHour);
    const hourTickedOver = isBefore(startOfHour(fullDate), Date.now());

    if (hourTickedOver && window.navigator.onLine) {
      loadUser();
    }
  };
github Wikiki / bulma-calendar / src / js / datePicker / index.js View on Github external
_select(date = undefined) {
		this.snapshot();
		date = type.isDate(date) ? date : new Date(date);
		if (this.options.isRange && (!this._isValidDate(this.start) || (this._isValidDate(this.start) && this._isValidDate(this.end)))) {
			this.start = date;
			this.end = undefined;
			this.emit('select:start', this);
		} else if (this.options.isRange && !this._isValidDate(this.end)) {
			if (dateFns.isBefore(date, this.start)) {
				this.end = this.start;
				this.start = date;
				this.emit('select', this);
			} else if (dateFns.isAfter(date, this.start)) {
				this.end = date;
				this.emit('select', this);
			} else if (this.options.allowSameDayRange) {
				this.end = date;
				this.emit('select', this);
			} else {
				this.start = date;
				this.end = undefined;
				this.emit('select:start', this);
			}
		} else {
			this.start = date;
github Adphorus / react-date-range / src / components / DayCell.js View on Github external
renderPreviewPlaceholder() {
    const { preview, day, styles } = this.props;
    if (!preview) return null;
    const startDate = preview.startDate ? endOfDay(preview.startDate) : null;
    const endDate = preview.endDate ? startOfDay(preview.endDate) : null;
    const isInRange =
      (!startDate || isAfter(day, startDate)) && (!endDate || isBefore(day, endDate));
    const isStartEdge = !isInRange && isSameDay(day, startDate);
    const isEndEdge = !isInRange && isSameDay(day, endDate);
    return (
      <span style="{{">
    );
  }
  renderSelectionPlaceholders() {</span>
github Kaniwani / kw-frontend / app / features / user / selectors.js View on Github external
  (lastLoad, isLoading, halfAMinuteAgo) => !isLoading && isBefore(lastLoad, halfAMinuteAgo)
);
github adarshpastakia / aurelia-ui-framework / src / forms / ui-date-range.ts View on Github external
protected weekChanged(week) {
    if (
      isWithinInterval(week, { start: this.minDate, end: this.maxDate }) ||
      isWithinInterval(endOfWeek(week), { start: this.minDate, end: this.maxDate })
    ) {
      this.start = isBefore(week, this.minDate) ? this.minDate : week;
      this.end = isAfter(endOfWeek(week), this.maxDate) ? this.maxDate : endOfWeek(week);
      this.startVm.currentMonth = startOfMonth(this.start);
      this.endVm.currentMonth = startOfMonth(this.end);
    }
  }
github osvaldokalvaitir / node-modulo3-novo / src / app / controllers / AppointmentController.js View on Github external
const isProvider = await User.findOne({
      where: { id: provider_id, provider: true },
    });

    if (!isProvider) {
      return res
        .status(401)
        .json({ error: 'You can only create appointmnets with providers' });
    }

    /**
     * Check for past dates
     */
    const hourStart = startOfHour(parseISO(date));

    if (isBefore(hourStart, new Date())) {
      return res.status(400).json({ error: 'Past dates are not permitted' });
    }

    /**
     * Check date availability
     */
    const checkAvailability = await Appointment.findOne({
      where: {
        provider_id,
        canceled_at: null,
        date: hourStart,
      },
    });

    if (checkAvailability) {
      return res
github ui-model / ui-model / projects / ui-model / common / src / lib / calendar / calendar.ts View on Github external
isPast(date: Date): boolean {
    return this._value && isBefore(date, this._value);
  }