How to use the ngx-bootstrap/chronos.shiftDate function in ngx-bootstrap

To help you get started, we’ve selected a few ngx-bootstrap 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 valor-software / ngx-bootstrap / src / datepicker / reducer / bs-datepicker.reducer.ts View on Github external
// use selected date on initial rendering if set
  let viewDate = state.view.date;

  if (state.view.mode === 'month') {
    const monthsCalendar = new Array(displayMonths);
    for (
      let calendarIndex = 0;
      calendarIndex < displayMonths;
      calendarIndex++
    ) {
      // todo: for unlinked calendars it will be harder
      monthsCalendar[calendarIndex] = formatMonthsCalendar(
        viewDate,
        getFormatOptions(state)
      );
      viewDate = shiftDate(viewDate, { year: 1 });
    }

    return Object.assign({}, state, { monthsCalendar });
  }

  if (state.view.mode === 'year') {
    const yearsCalendarModel = new Array(displayMonths);
    for (
      let calendarIndex = 0;
      calendarIndex < displayMonths;
      calendarIndex++
    ) {
      // todo: for unlinked calendars it will be harder
      yearsCalendarModel[calendarIndex] = formatYearsCalendar(
        viewDate,
        getFormatOptions(state)
github valor-software / ngx-bootstrap / src / datepicker / engine / flag-years-calendar.ts View on Github external
// todo: add check for linked calendars
  yearsCalendar.hideLeftArrow =
    options.yearIndex > 0 && options.yearIndex !== options.displayMonths;
  yearsCalendar.hideRightArrow =
    options.yearIndex < options.displayMonths &&
    options.yearIndex + 1 !== options.displayMonths;

  yearsCalendar.disableLeftArrow = isYearDisabled(
    shiftDate(yearsCalendar.years[0][0].date, { year: -1 }),
    options.minDate,
    options.maxDate
  );
  const i = yearsCalendar.years.length - 1;
  const j = yearsCalendar.years[i].length - 1;
  yearsCalendar.disableRightArrow = isYearDisabled(
    shiftDate(yearsCalendar.years[i][j].date, { year: 1 }),
    options.minDate,
    options.maxDate
  );

  return yearsCalendar;
}
github valor-software / ngx-bootstrap / src / datepicker / reducer / bs-datepicker.reducer.ts View on Github external
if (state.view.mode === 'year') {
    const yearsCalendarModel = new Array(displayMonths);

    for (
      let calendarIndex = 0;
      calendarIndex < displayMonths;
      calendarIndex++
    ) {
      // todo: for unlinked calendars it will be harder
      yearsCalendarModel[calendarIndex] = formatYearsCalendar(
        viewDate,
        getFormatOptions(state),
        state.minMode === 'year' ? getYearsCalendarInitialDate(state, calendarIndex) : undefined
      );
      viewDate = shiftDate(viewDate, { year: yearsPerCalendar });
    }

    return Object.assign({}, state, { yearsCalendarModel });
  }

  return state;
}
github valor-software / ngx-bootstrap / src / datepicker / engine / flag-months-calendar.ts View on Github external
) {
          monthCalendar.months[rowIndex][monthIndex] = newMonth;
        }
      });
    }
  );

  // todo: add check for linked calendars
  monthCalendar.hideLeftArrow =
    options.monthIndex > 0 && options.monthIndex !== options.displayMonths;
  monthCalendar.hideRightArrow =
    options.monthIndex < options.displayMonths &&
    options.monthIndex + 1 !== options.displayMonths;

  monthCalendar.disableLeftArrow = isYearDisabled(
    shiftDate(monthCalendar.months[0][0].date, { year: -1 }),
    options.minDate,
    options.maxDate
  );
  monthCalendar.disableRightArrow = isYearDisabled(
    shiftDate(monthCalendar.months[0][0].date, { year: 1 }),
    options.minDate,
    options.maxDate
  );

  return monthCalendar;
}
github valor-software / ngx-bootstrap / src / datepicker / reducer / bs-datepicker.reducer.ts View on Github external
return Object.assign({}, state, { monthsModel });
  }

  if (state.view.mode === 'month') {
    const monthsCalendar = new Array(displayMonths);
    for (
      let calendarIndex = 0;
      calendarIndex < displayMonths;
      calendarIndex++
    ) {
      // todo: for unlinked calendars it will be harder
      monthsCalendar[calendarIndex] = formatMonthsCalendar(
        viewDate,
        getFormatOptions(state)
      );
      viewDate = shiftDate(viewDate, { year: 1 });
    }

    return Object.assign({}, state, { monthsCalendar });
  }

  if (state.view.mode === 'year') {
    const yearsCalendarModel = new Array(displayMonths);

    for (
      let calendarIndex = 0;
      calendarIndex < displayMonths;
      calendarIndex++
    ) {
      // todo: for unlinked calendars it will be harder
      yearsCalendarModel[calendarIndex] = formatYearsCalendar(
        viewDate,
github valor-software / ngx-bootstrap / src / datepicker / engine / flag-days-calendar.ts View on Github external
week.days[dayIndex] = newDay;
      }
    });
  });

  // todo: add check for linked calendars
  formattedMonth.hideLeftArrow =
    options.isDisabled ||
    (options.monthIndex > 0 && options.monthIndex !== options.displayMonths);
  formattedMonth.hideRightArrow =
    options.isDisabled ||
    (options.monthIndex < options.displayMonths &&
      options.monthIndex + 1 !== options.displayMonths);

  formattedMonth.disableLeftArrow = isMonthDisabled(
    shiftDate(formattedMonth.month, { month: -1 }),
    options.minDate,
    options.maxDate
  );
  formattedMonth.disableRightArrow = isMonthDisabled(
    shiftDate(formattedMonth.month, { month: 1 }),
    options.minDate,
    options.maxDate
  );

  return formattedMonth;
}
github valor-software / ngx-bootstrap / src / datepicker / engine / format-years-calendar.ts View on Github external
function calculateInitialDate(viewDate: Date, previousInitialDate?: Date): Date {
  if (previousInitialDate
    && viewDate.getFullYear() >= previousInitialDate.getFullYear()
    && viewDate.getFullYear() < previousInitialDate.getFullYear() + yearsPerCalendar) {
    return previousInitialDate;
  }

  return shiftDate(viewDate, { year: initialYearShift });
}
github valor-software / ngx-bootstrap / src / datepicker / reducer / bs-datepicker.reducer.ts View on Github external
function shiftViewDate(state: BsDatepickerState, action: Action): Date {
  if (state.view.mode === 'year' && state.minMode === 'year') {
    const initialDate = getYearsCalendarInitialDate(state, 0);
    const middleDate = shiftDate(initialDate, { year: -initialYearShift });

    return shiftDate(middleDate, action.payload);
  }

  return shiftDate(startOf(state.view.date, 'month'), action.payload);
}
github valor-software / ngx-bootstrap / src / datepicker / utils / matrix-utils.ts View on Github external
export function createMatrix(
  options: MatrixOptions,
  fn: CreateMatrixCb
): T[][] {
  let prevValue = options.initialDate;
  const matrix: T[][] = new Array(options.height);
  for (let i = 0; i < options.height; i++) {
    matrix[i] = new Array(options.width);
    for (let j = 0; j < options.width; j++) {
      matrix[i][j] = fn(prevValue);
      prevValue = shiftDate(prevValue, options.shift);
    }
  }

  return matrix;
}