How to use the date-fns.addDays 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 gpbl / react-day-picker / package / lib / index.js View on Github external
function getWeeks(month, props) {
    var locale = props.locale, fixedWeeks = props.fixedWeeks;
    var monthStart = dateFns.startOfMonth(month);
    var monthEnd = dateFns.endOfMonth(month);
    var diff = dateFns.differenceInDays(monthEnd, monthStart);
    var weeks = {};
    var lastWeekStr = '';
    for (var i = 0; i <= diff; i++) {
        var date = dateFns.addDays(monthStart, i);
        var dateWithModifiers = new DateWithModifiers(date, {}, props);
        var week = dateFns.getWeek(dateWithModifiers.date, { locale: locale });
        if (week === 1 && dateFns.getMonth(date) === 11) {
            week = 53;
        }
        var weekStr = week.toString();
        if (!weeks[weekStr]) {
            var startDays = getOutsideStartDays(dateWithModifiers, props);
            // Create a new week by adding outside start days
            weeks[weekStr] = startDays;
        }
        weeks[weekStr].push(dateWithModifiers);
        lastWeekStr = weekStr;
    }
    var lastWeek = weeks[lastWeekStr];
    var lastDay = lastWeek[lastWeek.length - 1];
github Adphorus / react-date-range / src / components / DateRange.js View on Github external
const { ranges, onChange, maxDate, moveRangeOnFirstSelection } = this.props;
    const focusedRangeIndex = focusedRange[0];
    const selectedRange = ranges[focusedRangeIndex];
    if (!selectedRange || !onChange) return {};

    let { startDate, endDate } = selectedRange;
    if (!endDate) endDate = new Date(startDate);
    let nextFocusRange;
    if (!isSingleValue) {
      startDate = value.startDate;
      endDate = value.endDate;
    } else if (focusedRange[1] === 0) {
      // startDate selection
      const dayOffset = differenceInCalendarDays(endDate, startDate);
      startDate = value;
      endDate = moveRangeOnFirstSelection ? addDays(value, dayOffset) : value;
      if (maxDate) endDate = min([endDate, maxDate]);
      nextFocusRange = [focusedRange[0], 1];
    } else {
      endDate = value;
    }
    // reverse dates if startDate before endDate
    if (isBefore(endDate, startDate)) {
      [startDate, endDate] = [endDate, startDate];
    }

    if (!nextFocusRange) {
      const nextFocusRangeIndex = findNextRangeIndex(this.props.ranges, focusedRange[0]);
      nextFocusRange = [nextFocusRangeIndex, 0];
    }
    return {
      range: { startDate, endDate },
github nathanreyes / v-calendar / src / utils / mixins / root.js View on Github external
disabledAttribute() {
      // Build up a complete list of disabled dates
      let dates = [];
      // Initialize with disabled dates prop, if any
      if (this.disabledDates) {
        dates = isArray(this.disabledDates)
          ? this.disabledDates
          : [this.disabledDates];
      }
      // Add disabled dates for minDate and maxDate props
      const minDate = this.$locale.toDate(this.minDate);
      const maxDate = this.$locale.toDate(this.maxDate);
      if (minDate) {
        dates.push({ start: null, end: addDays(minDate, -1) });
      }
      if (maxDate) {
        dates.push({ start: addDays(maxDate, 1), end: null });
      }
      // Return the new disabled attribute
      return new Attribute(
        {
          key: 'disabled',
          dates,
          excludeDates: this.availableDates,
          excludeMode: 'includes',
          order: 100,
        },
        this.$theme,
        this.$locale,
      );
github pioug / cinelah / site / index.js View on Github external
.sort((a, b) => {
              if (parseInt(a.time) < 6) {
                a = addDays(parseISO(`${a.date}T${a.time}`), 1);
              } else {
                a = addDays(parseISO(`${a.date}T${a.time}`), 0);
              }

              if (parseInt(b.time) < 6) {
                b = addDays(parseISO(`${b.date}T${b.time}`), 1);
              } else {
                b = addDays(parseISO(`${b.date}T${b.time}`), 0);
              }

              if (isAfter(b, a)) return -1;
              if (isAfter(a, b)) return 1;
              return 0;
            })
            .map(showtime => {
github bullhorn / novo-elements / projects / novo-elements / src / elements / simple-table / cell-header.ts View on Github external
public filterData(filter?: any): void {
    let actualFilter = filter;
    if (this.config.filterConfig.type === 'date' && filter) {
      this.activeDateFilter = filter.label || this.labels.customDateRange;
      if (filter.startDate && filter.endDate) {
        actualFilter = {
          min: dateFns.startOfDay(filter.startDate.date),
          max: dateFns.startOfDay(dateFns.addDays(dateFns.startOfDay(filter.endDate.date), 1)),
        };
      } else {
        actualFilter = {
          min: filter.min ? dateFns.addDays(dateFns.startOfToday(), filter.min) : dateFns.startOfToday(),
          max: filter.max ? dateFns.addDays(dateFns.startOfTomorrow(), filter.max) : dateFns.startOfTomorrow(),
        };
      }
    }

    if (actualFilter && actualFilter.hasOwnProperty('value')) {
      actualFilter = filter.value;
    }

    if (this.changeTimeout) {
      clearTimeout(this.changeTimeout);
    }

    this.changeTimeout = setTimeout(() => {
      if (actualFilter === '') {
        actualFilter = undefined;
github pioug / cinelah / nuxt-server / pages / cinemas / _id.vue View on Github external
.sort((a, b) => {
                if (parseInt(a.time) < 6) {
                  a = addDays(parseISO(`${a.date} ${a.time}`), 1);
                } else {
                  a = addDays(parseISO(`${a.date} ${a.time}`), 0);
                }

                if (parseInt(b.time) < 6) {
                  b = addDays(parseISO(`${b.date} ${b.time}`), 1);
                } else {
                  b = addDays(parseISO(`${b.date} ${b.time}`), 0);
                }

                if (isAfter(b, a)) return -1;
                if (isAfter(a, b)) return 1;
                return 0;
              })
              .map(showtime => {
github kiwicom / margarita / packages / universal-components / src / RangeDatePicker / RangeDatePicker.stories.js View on Github external
constructor(props) {
    super(props);
    const from = addDays(new Date(), 1);
    const to = addDays(new Date(), 3);
    this.state = {
      dates: [from, to],
      tempDates: [from, to],
      nightsInDestination: [3, 6],
      isNightsInDestinationSelected: false,
      isVisible: false,
    };
  }
github DanielYKPan / date-time-picker / src / picker.component.ts View on Github external
private generateCalendar(): void {

        if (!this.pickerMoment) {
            return;
        }

        this.calendarDays = [];
        let startDateOfMonth = startOfMonth(this.pickerMoment);
        let startWeekdayOfMonth = getDay(startDateOfMonth);

        let dayDiff = 0 - (startWeekdayOfMonth + (7 - this.locale.firstDayOfWeek)) % 7;

        for (let i = 1; i < 7; i++) {
            let week = [];
            for (let j = 0; j < 7; j++) {
                let date = addDays(startDateOfMonth, dayDiff);
                let inOtherMonth = !isSameMonth(date, this.pickerMoment);
                week.push({
                    date,
                    num: getDate(date),
                    today: isSameDay(this.now, date),
                    otherMonth: inOtherMonth,
                    hide: !this.showOtherMonths && inOtherMonth,
                });
                dayDiff += 1;
            }
            this.calendarDays.push(week);
        }

        this.pickerMonth = this.locale.monthNames[getMonth(this.pickerMoment)];
        this.pickerYear = getYear(this.pickerMoment).toString();
    }
github gregnb / react-use-calendar / src / index.js View on Github external
function reducer(state, action) {
  switch (action.type) {
    case actionTypes.SET_OPTIONS:
      return { ...state, ...createEvents(action.options, state), options: { ...state.options, ...action.options } };
    case actionTypes.SET_DATE:
      return { ...state, ...getDays(action.date, state) };
    case actionTypes.GET_NEXT_MONTH:
      return { ...state, ...getDays(addDays(state.startDate, 30), state) };
    case actionTypes.GET_PREV_MONTH:
      return { ...state, ...getDays(addDays(state.startDate, -30), state) };
    case actionTypes.ADD_EVENT:
      return { ...state, ...addEvent(action.event, state) };
    case actionTypes.REMOVE_EVENT:
      return { ...state, ...removeEvent(action.id, state) };
    default:
      return state;
  }
}
github adarshpastakia / aurelia-ui-framework / dist / native-modules / ui-calendar.js View on Github external
var parseDate = function (date) {
    if (isString(date)) {
        var dt = startOfMinute(new Date());
        if (date.startsWith(CALENDAR_GRAIN.DAY)) {
            return addDays(dt, parseInt(date.replace(CALENDAR_GRAIN.DAY, "") || "0", 10));
        }
        else if (date.startsWith(CALENDAR_GRAIN.WEEK)) {
            return addWeeks(dt, parseInt(date.replace(CALENDAR_GRAIN.WEEK, "") || "0", 10));
        }
        else if (date.startsWith(CALENDAR_GRAIN.MONTH)) {
            return addMonths(dt, parseInt(date.replace(CALENDAR_GRAIN.MONTH, "") || "0", 10));
        }
        else if (date.startsWith(CALENDAR_GRAIN.YEAR)) {
            return addYears(dt, parseInt(date.replace(CALENDAR_GRAIN.YEAR, "") || "0", 10));
        }
        else {
            return parseISO(date);
        }
    }
    else if (date) {
        return date;