UNPKG

@iro/calendar

Version:

lunar is a calendar library for Solar and Chinese Lunar.

135 lines 4.7 kB
import { LunarUtil } from './LunarUtil'; import { LunarYear } from './LunarYear'; import { Solar } from './Solar'; import { NineStar } from './NineStar'; var LunarMonth = (function () { function LunarMonth(lunarYear, lunarMonth, dayCount, firstJulianDay) { this._year = lunarYear; this._month = lunarMonth; this._dayCount = dayCount; this._firstJulianDay = firstJulianDay; } LunarMonth.fromYm = function (lunarYear, lunarMonth) { return LunarYear.fromYear(lunarYear).getMonth(lunarMonth); }; LunarMonth.prototype.getYear = function () { return this._year; }; LunarMonth.prototype.getMonth = function () { return this._month; }; LunarMonth.prototype.isLeap = function () { return this._month < 0; }; LunarMonth.prototype.getDayCount = function () { return this._dayCount; }; LunarMonth.prototype.getFirstJulianDay = function () { return this._firstJulianDay; }; LunarMonth.prototype.getPositionTaiSui = function () { var p; var m = Math.abs(this._month); switch (m) { case 1: case 5: case 9: p = '艮'; break; case 3: case 7: case 11: p = '坤'; break; case 4: case 8: case 12: p = '巽'; break; default: p = LunarUtil.POSITION_GAN[Solar.fromJulianDay(this.getFirstJulianDay()).getLunar().getMonthGanIndex()]; } return p; }; LunarMonth.prototype.getPositionTaiSuiDesc = function () { return LunarUtil.POSITION_DESC.get(this.getPositionTaiSui()); }; LunarMonth.prototype.getNineStar = function () { var index = LunarYear.fromYear(this._year).getZhiIndex() % 3; var m = Math.abs(this._month); var monthZhiIndex = (13 + m) % 12; var n = 27 - (index * 3); if (monthZhiIndex < LunarUtil.BASE_MONTH_ZHI_INDEX) { n -= 3; } var offset = (n - monthZhiIndex) % 9; return NineStar.fromIndex(offset); }; LunarMonth.prototype.toString = function () { return "".concat(this.getYear(), "\u5E74").concat(this.isLeap() ? '闰' : '').concat(LunarUtil.MONTH[Math.abs(this.getMonth())], "\u6708(").concat(this.getDayCount(), ")\u5929"); }; LunarMonth.prototype.next = function (n) { if (0 == n) { return LunarMonth.fromYm(this._year, this._month); } else { var rest = Math.abs(n); var ny = this._year; var iy = ny; var im = this._month; var index = 0; var months = LunarYear.fromYear(ny).getMonths(); var i = void 0; var m = void 0; var size = void 0; if (n > 0) { while (true) { size = months.length; for (i = 0; i < size; i++) { m = months[i]; if (m.getYear() === iy && m.getMonth() === im) { index = i; break; } } var more = size - index - 1; if (rest < more) { break; } rest -= more; var lastMonth = months[size - 1]; iy = lastMonth.getYear(); im = lastMonth.getMonth(); ny++; months = LunarYear.fromYear(ny).getMonths(); } return months[index + rest]; } else { while (true) { size = months.length; for (i = 0; i < size; i++) { m = months[i]; if (m.getYear() === iy && m.getMonth() === im) { index = i; break; } } if (rest <= index) { break; } rest -= index; var firstMonth = months[0]; iy = firstMonth.getYear(); im = firstMonth.getMonth(); ny--; months = LunarYear.fromYear(ny).getMonths(); } return months[index - rest]; } } }; return LunarMonth; }()); export { LunarMonth }; //# sourceMappingURL=LunarMonth.js.map