UNPKG

wix-style-react

Version:
69 lines (62 loc) 2.06 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import addMonths from 'date-fns/addMonths'; import startOfMonth from 'date-fns/startOfMonth'; import endOfMonth from 'date-fns/endOfMonth'; import endOfDay from 'date-fns/endOfDay'; import isWithinInterval from 'date-fns/isWithinInterval'; import isAfter from 'date-fns/isAfter'; import isBefore from 'date-fns/isBefore'; import differenceInCalendarDays from 'date-fns/differenceInCalendarDays'; /** * Date utils for a multi-month calendar view. */ export var CalendarView = /*#__PURE__*/function () { /** * @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 */ function CalendarView(firstMonthDate, numOfMonths) { _classCallCheck(this, CalendarView); this.startDate = startOfMonth(firstMonthDate); this.endDate = endOfDay(endOfMonth(addMonths(this.startDate, numOfMonths - 1))); } /** * Is the given date contained in the calendar view * * @param {*} date * @returns * @memberof CalendarView */ _createClass(CalendarView, [{ key: "isContained", value: function isContained(date) { return isWithinInterval(date, { start: this.startDate, end: this.endDate }); } }, { key: "isRangeFits", value: function isRangeFits(from, to) { return differenceInCalendarDays(to, from) <= differenceInCalendarDays(this.endDate, this.startDate); } /** * Is the given date after the view's end date */ }, { key: "isAfterView", value: function isAfterView(date) { return isAfter(date, this.endDate); } /** * Is the given date before the view's start date */ }, { key: "isBeforeView", value: function isBeforeView(date) { return isBefore(date, this.startDate); } }]); return CalendarView; }();