"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimeUnit = exports.EorzeaTime = void 0;
const format_1 = require("./format");
class EorzeaTime {
    constructor(time) {
        const timeNum = !time ? new Date().getTime() : (typeof time === "number") ? time : time.getTime();
        const eorzeaTimeNum = Math.floor(timeNum / 1000 * 3600 / 175);
        this.year = Math.floor(eorzeaTimeNum / TimeUnit.YEAR) + 1;
        this.month = Math.floor((eorzeaTimeNum / TimeUnit.MONTH) % 12) + 1;
        this.day = Math.floor((eorzeaTimeNum / TimeUnit.DAY) % 32) + 1;
        this.hour = Math.floor((eorzeaTimeNum / TimeUnit.HOUR) % 24);
        this.minute = Math.floor((eorzeaTimeNum / TimeUnit.MINUTE) % 60);
        this.second = Math.floor((eorzeaTimeNum / TimeUnit.SECOND) % 60);
    }
    toTimeString() {
        return `${(0, format_1.prefixNum)(this.hour)}:${(0, format_1.prefixNum)(this.minute)}`;
    }
    /**
     * 艾欧泽亚时间戳
     */
    getTime() {
        return this.second * TimeUnit.SECOND +
            this.minute * TimeUnit.MINUTE +
            this.hour * TimeUnit.HOUR +
            (this.day - 1) * TimeUnit.DAY +
            (this.month - 1) * TimeUnit.MONTH +
            (this.year - 1) * TimeUnit.YEAR;
    }
    setHour(hour) {
        this.hour = hour;
        return this;
    }
    setMinute(minute) {
        this.minute = minute;
        return this;
    }
    /**
     * 计算距离当前艾欧泽亚时间最近的下一个地球时间。
     */
    toNextEarthTime() {
        const second = this.second;
        this.second = 0;
        const timeNum = this.getTime() * 175 / 3600 * 1000;
        this.second = second;
        const time = new Date(timeNum);
        const now = new Date();
        const DAY = 24 * 60 * 175 / 3600;
        while (time.getTime() <= now.getTime())
            time.setMinutes(time.getMinutes() + DAY);
        return time;
    }
}
exports.EorzeaTime = EorzeaTime;
var TimeUnit;
(function (TimeUnit) {
    TimeUnit[TimeUnit["SECOND"] = 1] = "SECOND";
    TimeUnit[TimeUnit["MINUTE"] = 60] = "MINUTE";
    TimeUnit[TimeUnit["HOUR"] = 3600] = "HOUR";
    TimeUnit[TimeUnit["DAY"] = 86400] = "DAY";
    TimeUnit[TimeUnit["MONTH"] = 2764800] = "MONTH";
    TimeUnit[TimeUnit["YEAR"] = 33177600] = "YEAR";
})(TimeUnit = exports.TimeUnit || (exports.TimeUnit = {}));
