How to use the date-fns/is_before 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 ThymeApp / thyme / src / sections / TimeSheet / components / Entry / New.js View on Github external
onStartTimeTracking = () => {
    const { now } = this.props;
    const { entry } = this.state;

    const startTime = new Date();

    const isOldTempItem = isBefore(entry.start, addDays(now, -1));
    const isNewTempItem = isEqual(entry.start, startOfDay(now));

    const newEntry = {
      ...entry,
      start: isOldTempItem || isNewTempItem ? startTime : entry.start,
      end: startTime,
    };

    this.onUpdateItem(newEntry, true);

    this.setState({
      tracking: true,
      entry: newEntry,
    });

    // track event
github toptal / simple-react-calendar / src / calendar / month.tsx View on Github external
let date = startOfWeek(startOfMonth(activeMonth), { weekStartsOn })
    const end = endOfWeek(endOfMonth(activeMonth), { weekStartsOn })

    // TODO: simplify with FC approach, remove state logic from child components
    //       this is passed from the parent component
    // @ts-ignore
    if (this._selectionInProgress && rangeLimit) {
      minDate = this._getMinDate()
      maxDate = this._getMaxDate()
    }

    while (
      // TODO: External helper with weeknumber etc
      /* eslint-disable no-unmodified-loop-condition */
      (typeof minNumberOfWeeks === 'number' && minNumberOfWeeks > weeks.length) ||
      (isBefore(date, end) || isSameDay(date, end))
    ) {
      weeks.push(date)
      date = addDays(date, 7)
    }

    return weeks.map((week) => {
      return (
github toptal / simple-react-calendar / src / calendar / month.tsx View on Github external
_pushUpdate() {
    const { onChange, rangeLimit } = this.props
    let start, end

    // TODO: simplify with FC approach, remove state logic from child components
    //       this is passed from the parent component
    // @ts-ignore
    if (this._selectionStart && this._selectionEnd) {
      // TODO: simplify with FC approach, remove state logic from child components
      //       this is passed from the parent component
      // @ts-ignore
      if (isBefore(this._selectionStart, this._selectionEnd)) {
        // TODO: simplify with FC approach, remove state logic from child components
        //       this is passed from the parent component
        // @ts-ignore
        start = this._selectionStart
        // TODO: simplify with FC approach, remove state logic from child components
        //       this is passed from the parent component
        // @ts-ignore
        end = this._selectionEnd
      } else {
        // TODO: simplify with FC approach, remove state logic from child components
        //       this is passed from the parent component
        // @ts-ignore
        start = this._selectionEnd
        // TODO: simplify with FC approach, remove state logic from child components
        //       this is passed from the parent component
        // @ts-ignore
github MikaelEdebro / vue-airbnb-style-datepicker / src / components / AirbnbStyleDatepicker.vue View on Github external
isHoveredInRange(date) {
      if (this.isSingleMode || this.allDatesSelected) {
        return false
      }

      return (
        (isAfter(date, this.selectedDate1) && isBefore(date, this.hoverDate)) ||
        (isAfter(date, this.hoverDate) && isBefore(date, this.selectedDate1))
      )
    },
    isBeforeMinDate(date) {
github frontsideair / savethedate / src / utils.js View on Github external
export function withinRange(date: Date, { start, end }: { start: Date | null, end: Date | null }) {
  if (start === null) {
    if (end === null) {
      return true;
    } else {
      return isBefore(date, end);
    }
  } else {
    if (end === null) {
      return isAfter(date, start);
    } else {
      return isWithinRange(date, start, end);
    }
  }
}
github rubencodes / recal / src / docs / DateRangePicker.jsx View on Github external
isDateEnabled(date) {
		const now = new Date();
		const todayDay = now.getDate();
		const todayMonth = now.getMonth();
		const todayYear = now.getFullYear();
		const today = new Date(todayYear, todayMonth, todayDay);

		return !isBefore(date, today);
	}
	onStartDateSelected(date) {
github toptal / simple-react-calendar / src / calendar / month.jsx View on Github external
} = event
    const date = parse(value)

    const {onDayMouseEnter} = this.props

    if (onDayMouseEnter) {
      onDayMouseEnter(date)
    }

    if (!this._selectionInProgress) return

    const {rangeLimit} = this.props
    const dateLimit = subDays(this._selectionStart, rangeLimit)

    const isDisabledWithin = this._getDisabledRange({
      start: isBefore(this._selectionStart, date) ? this._selectionStart : date,
      end: !isBefore(this._selectionStart, date) ? this._selectionStart : date,
    })

    if (!isDisabledWithin) return

    if (!isEqual(date, this._selectionEnd)) {
      if (!rangeLimit || (rangeLimit && !isBefore(date, dateLimit))) {
        this._selectionEnd = date
        this._pushUpdate()
      }
    }
  }
github clauderic / react-infinite-calendar / src / Calendar / withRange.js View on Github external
function getSortedSelection({start, end}) {
  return isBefore(start, end)
    ? {start, end}
    : {start: end, end: start};
}
github MikaelEdebro / vue-airbnb-style-datepicker / src / components / AirbnbStyleDatepicker.vue View on Github external
isBeforeMinDate(date) {
      if (!this.minDate) {
        return false
      }
      return isBefore(date, this.minDate)
    },
    isAfterEndDate(date) {
github vuikit / vuikit / src / components / datepicker / header.js View on Github external
function getYearsRange (startDate, endDate) {
  const years = []
  let curDate = startDate
  while (isBefore(curDate, endDate)) {
    years.push(getYear(curDate))
    curDate = addYears(curDate, 1)
  }
  return years
}