UNPKG

@iro/calendar

Version:

lunar is a calendar library for Solar and Chinese Lunar.

167 lines 6.43 kB
import { LunarUtil } from './LunarUtil'; import { Lunar } from './Lunar'; import { NineStar } from './NineStar'; var LunarTime = (function () { function LunarTime(lunarYear, lunarMonth, lunarDay, hour, minute, second) { this._lunar = Lunar.fromYmdHms(lunarYear, lunarMonth, lunarDay, hour, minute, second); this._zhiIndex = LunarUtil.getTimeZhiIndex([(hour < 10 ? '0' : '') + hour, (minute < 10 ? '0' : '') + minute].join(':')); this._ganIndex = (this._lunar.getDayGanIndexExact() % 5 * 2 + this._zhiIndex) % 10; } LunarTime.fromYmdHms = function (lunarYear, lunarMonth, lunarDay, hour, minute, second) { return new LunarTime(lunarYear, lunarMonth, lunarDay, hour, minute, second); }; LunarTime.prototype.getGanIndex = function () { return this._ganIndex; }; LunarTime.prototype.getZhiIndex = function () { return this._zhiIndex; }; LunarTime.prototype.getGan = function () { return LunarUtil.GAN[this._ganIndex + 1]; }; LunarTime.prototype.getZhi = function () { return LunarUtil.ZHI[this._zhiIndex + 1]; }; LunarTime.prototype.getGanZhi = function () { return this.getGan() + this.getZhi(); }; LunarTime.prototype.getShengXiao = function () { return LunarUtil.SHENGXIAO[this._zhiIndex + 1]; }; LunarTime.prototype.getPositionXi = function () { return LunarUtil.POSITION_XI[this._ganIndex + 1]; }; LunarTime.prototype.getPositionXiDesc = function () { return LunarUtil.POSITION_DESC.get(this.getPositionXi()); }; LunarTime.prototype.getPositionYangGui = function () { return LunarUtil.POSITION_YANG_GUI[this._ganIndex + 1]; }; LunarTime.prototype.getPositionYangGuiDesc = function () { return LunarUtil.POSITION_DESC.get(this.getPositionYangGui()); }; LunarTime.prototype.getPositionYinGui = function () { return LunarUtil.POSITION_YIN_GUI[this._ganIndex + 1]; }; LunarTime.prototype.getPositionYinGuiDesc = function () { return LunarUtil.POSITION_DESC.get(this.getPositionYinGui()); }; LunarTime.prototype.getPositionFu = function (sect) { if (sect === void 0) { sect = 2; } return (1 === sect ? LunarUtil.POSITION_FU : LunarUtil.POSITION_FU_2)[this._ganIndex + 1]; }; LunarTime.prototype.getPositionFuDesc = function (sect) { if (sect === void 0) { sect = 2; } return LunarUtil.POSITION_DESC.get(this.getPositionFu(sect)); }; LunarTime.prototype.getPositionCai = function () { return LunarUtil.POSITION_CAI[this._ganIndex + 1]; }; LunarTime.prototype.getPositionCaiDesc = function () { return LunarUtil.POSITION_DESC.get(this.getPositionCai()); }; LunarTime.prototype.getNaYin = function () { return LunarUtil.NAYIN.get(this.getGanZhi()); }; LunarTime.prototype.getTianShen = function () { return LunarUtil.TIAN_SHEN[(this._zhiIndex + LunarUtil.ZHI_TIAN_SHEN_OFFSET.get(this._lunar.getDayZhiExact())) % 12 + 1]; }; LunarTime.prototype.getTianShenType = function () { return LunarUtil.TIAN_SHEN_TYPE.get(this.getTianShen()); }; LunarTime.prototype.getTianShenLuck = function () { return LunarUtil.TIAN_SHEN_TYPE_LUCK.get(this.getTianShenType()); }; LunarTime.prototype.getChong = function () { return LunarUtil.CHONG[this._zhiIndex]; }; LunarTime.prototype.getSha = function () { return LunarUtil.SHA.get(this.getZhi()); }; LunarTime.prototype.getChongShengXiao = function () { var chong = this.getChong(); for (var i = 0, j = LunarUtil.ZHI.length; i < j; i++) { if (LunarUtil.ZHI[i] === chong) { return LunarUtil.SHENGXIAO[i]; } } return ''; }; LunarTime.prototype.getChongDesc = function () { return '(' + this.getChongGan() + this.getChong() + ')' + this.getChongShengXiao(); }; LunarTime.prototype.getChongGan = function () { return LunarUtil.CHONG_GAN[this._ganIndex]; }; LunarTime.prototype.getChongGanTie = function () { return LunarUtil.CHONG_GAN_TIE[this._ganIndex]; }; LunarTime.prototype.getYi = function () { return LunarUtil.getTimeYi(this._lunar.getDayInGanZhiExact(), this.getGanZhi()); }; LunarTime.prototype.getJi = function () { return LunarUtil.getTimeJi(this._lunar.getDayInGanZhiExact(), this.getGanZhi()); }; LunarTime.prototype.getNineStar = function () { var solarYmd = this._lunar.getSolar().toYmd(); var jieQi = this._lunar.getJieQiTable(); var asc = false; if (solarYmd >= jieQi.get('冬至').toYmd() && solarYmd < jieQi.get('夏至').toYmd()) { asc = true; } var start = asc ? 7 : 3; var dayZhi = this._lunar.getDayZhi(); if ('子午卯酉'.indexOf(dayZhi) > -1) { start = asc ? 1 : 9; } else if ('辰戌丑未'.indexOf(dayZhi) > -1) { start = asc ? 4 : 6; } var index = asc ? start + this._zhiIndex - 1 : start - this._zhiIndex - 1; if (index > 8) { index -= 9; } if (index < 0) { index += 9; } return NineStar.fromIndex(index); }; LunarTime.prototype.getXun = function () { return LunarUtil.getXun(this.getGanZhi()); }; LunarTime.prototype.getXunKong = function () { return LunarUtil.getXunKong(this.getGanZhi()); }; LunarTime.prototype.getMinHm = function () { var hour = this._lunar.getHour(); if (hour < 1) { return '00:00'; } else if (hour > 22) { return '23:00'; } if (hour % 2 === 0) { hour -= 1; } return (hour < 10 ? '0' : '') + hour + ':00'; }; LunarTime.prototype.getMaxHm = function () { var hour = this._lunar.getHour(); if (hour < 1) { return '00:59'; } else if (hour > 22) { return '23:59'; } if (hour % 2 !== 0) { hour += 1; } return (hour < 10 ? '0' : '') + hour + ':59'; }; LunarTime.prototype.toString = function () { return this.getGanZhi(); }; return LunarTime; }()); export { LunarTime }; //# sourceMappingURL=LunarTime.js.map