"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.CalendarView = void 0;
var _addMonths = _interopRequireDefault(require("date-fns/addMonths"));
var _startOfMonth = _interopRequireDefault(require("date-fns/startOfMonth"));
var _endOfMonth = _interopRequireDefault(require("date-fns/endOfMonth"));
var _endOfDay = _interopRequireDefault(require("date-fns/endOfDay"));
var _isWithinInterval = _interopRequireDefault(require("date-fns/isWithinInterval"));
var _isAfter = _interopRequireDefault(require("date-fns/isAfter"));
var _isBefore = _interopRequireDefault(require("date-fns/isBefore"));
var _differenceInCalendarDays = _interopRequireDefault(require("date-fns/differenceInCalendarDays"));
/**
 * Date utils for a multi-month calendar view.
 */
class CalendarView {
  /**
   * @param {*} firstMonthDate a date that represents the first displayed month in the calendar view. (Does not have to be the 1st of that month)
   * @param {*} numOfMonths number of months that are displayed in the view
   */
  constructor(firstMonthDate, numOfMonths) {
    this.startDate = (0, _startOfMonth.default)(firstMonthDate);
    this.endDate = (0, _endOfDay.default)((0, _endOfMonth.default)((0, _addMonths.default)(this.startDate, numOfMonths - 1)));
  }

  /**
   * Is the given date contained in the calendar view
   *
   * @param {*} date
   * @returns
   * @memberof CalendarView
   */
  isContained(date) {
    return (0, _isWithinInterval.default)(date, {
      start: this.startDate,
      end: this.endDate
    });
  }
  isRangeFits(from, to) {
    return (0, _differenceInCalendarDays.default)(to, from) <= (0, _differenceInCalendarDays.default)(this.endDate, this.startDate);
  }

  /**
   * Is the given date after the view's end date
   */
  isAfterView(date) {
    return (0, _isAfter.default)(date, this.endDate);
  }

  /**
   * Is the given date before the view's start date
   */
  isBeforeView(date) {
    return (0, _isBefore.default)(date, this.startDate);
  }
}
exports.CalendarView = CalendarView;
//# sourceMappingURL=utils.js.map