@studyportals/sp-hs-misc
Version:
Miscellaneous code used in HouseStark's projects
73 lines (66 loc) • 2.96 kB
JavaScript
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
//# sourceMappingURL=time-interval.class.js.map
var TimeInterval = function () {
_createClass(TimeInterval, [{
key: "startDate",
get: function get() {
return this._startDate;
}
}, {
key: "endDate",
get: function get() {
return this._endDate;
}
}]);
function TimeInterval(startDate, endDate) {
_classCallCheck(this, TimeInterval);
if (endDate < startDate) {
throw new Error("TimeInterval constructor was called with a endDate that is earlier than the beginDate");
}
this._startDate = startDate;
this._endDate = endDate;
}
_createClass(TimeInterval, [{
key: "isDateInInterval",
/**
* @deprecated Use TimeInterval.contains instead.
*/
value: function isDateInInterval(date) {
return this.contains(date);
}
}, {
key: "contains",
value: function contains(date) {
return this.startDate <= date && date <= this.endDate;
}
}, {
key: "toUTCDays",
value: function toUTCDays() {
var days = [];
var millisecondsInADay = 24 * 60 * 60 * 1000;
var lastDayUnixEpoch = Date.UTC(this.endDate.getUTCFullYear(), this.endDate.getUTCMonth(), this.endDate.getUTCDate());
var firstDayUnixEpoch = Date.UTC(this.startDate.getUTCFullYear(), this.startDate.getUTCMonth(), this.startDate.getUTCDate());
var currentDayUnixEpoch = firstDayUnixEpoch;
while (currentDayUnixEpoch <= lastDayUnixEpoch) {
days.push(new Date(currentDayUnixEpoch));
currentDayUnixEpoch += millisecondsInADay;
}
return days;
}
}, {
key: "toJSON",
value: function toJSON() {
var obj = {};
obj.startDate = this.startDate;
obj.endDate = this.endDate;
return obj;
}
}], [{
key: "createFromTimeInterval",
value: function createFromTimeInterval(timeInterval) {
return new TimeInterval(timeInterval.startDate, timeInterval.endDate);
}
}]);
return TimeInterval;
}();