UNPKG

@adaptabletools/adaptable-cjs

Version:

Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

57 lines (56 loc) 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CalendarApiImpl = void 0; const ApiBase_1 = require("./ApiBase"); class CalendarApiImpl extends ApiBase_1.ApiBase { getNextWorkingDay() { let counterDate = new Date(); let isWorkingDay = false; while (!isWorkingDay) { counterDate.setDate(counterDate.getDate() + 1); isWorkingDay = this.isWorkingDay(counterDate); } return counterDate; } getPreviousWorkingDay() { let counterDate = new Date(); let isWorkingDay = false; while (!isWorkingDay) { counterDate.setDate(counterDate.getDate() - 1); isWorkingDay = this.isWorkingDay(counterDate); } return counterDate; } isWorkingDay(dateToCheck) { const holidays = this.getHolidays(); if (!holidays) { return dateToCheck.getDay() != 0 && dateToCheck.getDay() != 6; } for (let holiday of holidays) { if (holiday.setHours(0, 0, 0, 0) == dateToCheck.setHours(0, 0, 0, 0)) { return false; } } return dateToCheck.getDay() != 0 && dateToCheck.getDay() != 6; } isHoliday(dateToCheck) { return !this.isWorkingDay(dateToCheck); } isSameDay(firstDateToCheck, secondDateToCheck) { return (firstDateToCheck.getFullYear() === secondDateToCheck.getFullYear() && firstDateToCheck.getMonth() === secondDateToCheck.getMonth() && firstDateToCheck.getDate() === secondDateToCheck.getDate()); } getHolidays() { const holidays = this.getCalendarOptions().holidays; if (holidays) { if (typeof holidays === 'function') { return holidays(this.getAdaptableInternalApi().buildBaseContext()); } else { return holidays; } } } } exports.CalendarApiImpl = CalendarApiImpl;