"use strict";

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

module.exports = {

	getSeasonAndDay(specifiedDate = null, callback) {
		var _this = this;

		return _asyncToGenerator(function* () {

			if (typeof specifiedDate === 'function') {
				callback = specifiedDate;
				specifiedDate = null;
			}

			try {

				// Get season from settings
				let season = yield _this.settings.getAsync('currentSeason');

				let seasonDate = new Date(season.Date);
				let now = new Date().getTime();
				let seasonStart = seasonDate.getTime();
				let oneDay = 24 * 60 * 60 * 1000;
				let oneSeason = 28 * 24 * 60 * 60 * 1000;

				if (!specifiedDate) {

					let currentDay = Math.floor((now - seasonStart) / oneDay) + 1;

					// Handle if day goes over 28
					currentDay = currentDay % 28;

					callback(null, { season: season.Season, day: currentDay });
				} else {

					// Get season 1 start
					let season1Start = seasonStart - (season.Season - 1) * oneSeason;

					// Get season
					let specifiedTime = specifiedDate.getTime() - season1Start;
					let specifiedSeason = Math.floor(specifiedTime / oneSeason) + 1;
					let timeLeftInSeason = specifiedTime - (specifiedSeason - 1) * oneSeason;
					let specifiedDay = Math.floor(timeLeftInSeason / oneDay) + 1;

					// Get day
					callback(null, { season: specifiedSeason, day: specifiedDay });
				}
			} catch (err) {
				_this.errorInternal(err);
			}
		})();
	}

};
//# sourceMappingURL=date.js.map