@kamiazya/freebusy
Version:
Determine free blocks from a list of events.
77 lines • 2.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var DateTimeValidator_1 = require("./DateTimeValidator");
/**
* Scope on the time used to get free time.
*/
var ScopeTime = /** @class */ (function () {
function ScopeTime(option) {
// override default when option is not seted.
var defaultStart = 0;
if (option && option.defaultStart) {
defaultStart = option.defaultStart;
}
var defaultEnd = 24;
if (option && option.defaultEnd) {
defaultEnd = option.defaultEnd;
}
// validate so that incorrect date and time will not be set
DateTimeValidator_1.DateTimeValidator
.validateHour(defaultStart, 'set default start time between 0 and 24.')
.validateHour(defaultEnd, 'set default end time between 0 and 24.')
.validateStartHourAndEndHour(defaultStart, defaultEnd, 'start is larger then end.');
this.starts = new Array(7).fill(defaultStart);
this.ends = new Array(7).fill(defaultEnd);
}
/**
* Set start time to day of week.
*
* @param day day of week.
* 0(Sunday) and 6(Saturday)
* @param hour start hour of day.
* between 0 and 24.
*/
ScopeTime.prototype.setStart = function (day, hour) {
DateTimeValidator_1.DateTimeValidator
.validateDay(day, 'day should be between 0(Sunday) and 6(Saturday).')
.validateHour(hour, 'set start time between 0 and 24.');
this.starts[day] = hour;
};
/**
* Set end time to day of week.
*
* @param day day of week.
* 0(Sunday) and 6(Saturday)
* @param hour end hour of day.
* between 0 and 24.
*/
ScopeTime.prototype.setEnd = function (day, hour) {
DateTimeValidator_1.DateTimeValidator
.validateDay(day, 'day should be between 0(Sunday) and 6(Saturday).')
.validateHour(hour, 'set end time between 0 and 24.');
this.ends[day] = hour;
};
/**
* Get start hour for given day of week.
*
* @param day day of week
*/
ScopeTime.prototype.start = function (day) {
DateTimeValidator_1.DateTimeValidator
.validateDay(day, 'day should be between 0(Sunday) and 6(Saturday).');
return this.starts[day];
};
/**
* Get end hour for given day of week.
*
* @param day day of week
*/
ScopeTime.prototype.end = function (day) {
DateTimeValidator_1.DateTimeValidator
.validateDay(day, 'day should be between 0(Sunday) and 6(Saturday).');
return this.ends[day];
};
return ScopeTime;
}());
exports.ScopeTime = ScopeTime;
//# sourceMappingURL=ScopeTime.js.map