@iro/calendar
Version:
lunar is a calendar library for Solar and Chinese Lunar.
139 lines • 4.81 kB
JavaScript
import { Lunar } from './Lunar';
import { LunarUtil } from './LunarUtil';
import { TaoUtil } from './TaoUtil';
import { TaoFestival } from './TaoFestival';
var Tao = (function () {
function Tao(lunar) {
this._lunar = lunar;
}
Tao.fromLunar = function (lunar) {
return new Tao(lunar);
};
Tao.fromYmdHms = function (lunarYear, lunarMonth, lunarDay, hour, minute, second) {
return Tao.fromLunar(Lunar.fromYmdHms(lunarYear + Tao.BIRTH_YEAR, lunarMonth, lunarDay, hour, minute, second));
};
Tao.fromYmd = function (lunarYear, lunarMonth, lunarDay) {
return Tao.fromYmdHms(lunarYear, lunarMonth, lunarDay, 0, 0, 0);
};
Tao.prototype.getLunar = function () {
return this._lunar;
};
Tao.prototype.getYear = function () {
return this._lunar.getYear() - Tao.BIRTH_YEAR;
};
Tao.prototype.getMonth = function () {
return this._lunar.getMonth();
};
Tao.prototype.getDay = function () {
return this._lunar.getDay();
};
Tao.prototype.getYearInChinese = function () {
var y = this.getYear() + '';
var s = '';
var zero = '0'.charCodeAt(0);
for (var i = 0, j = y.length; i < j; i++) {
s += LunarUtil.NUMBER[y.charCodeAt(i) - zero];
}
return s;
};
Tao.prototype.getMonthInChinese = function () {
return this._lunar.getMonthInChinese();
};
Tao.prototype.getDayInChinese = function () {
return this._lunar.getDayInChinese();
};
Tao.prototype.getFestivals = function () {
var l = [];
var fs = TaoUtil.FESTIVAL.get(this.getMonth() + '-' + this.getDay());
if (fs) {
fs.forEach(function (f) {
l.push(f);
});
}
var jq = this._lunar.getJieQi();
if ('冬至' === jq) {
l.push(new TaoFestival('元始天尊圣诞'));
}
else if ('夏至' === jq) {
l.push(new TaoFestival('灵宝天尊圣诞'));
}
var f = TaoUtil.BA_JIE.get(jq);
if (f) {
l.push(new TaoFestival(f));
}
f = TaoUtil.BA_HUI.get(this._lunar.getDayInGanZhi());
if (f) {
l.push(new TaoFestival(f));
}
return l;
};
Tao.prototype._isDayIn = function (days) {
var md = this.getMonth() + '-' + this.getDay();
for (var i = 0, j = days.length; i < j; i++) {
if (md === days[i]) {
return true;
}
}
return false;
};
Tao.prototype.isDaySanHui = function () {
return this._isDayIn(TaoUtil.SAN_HUI);
};
Tao.prototype.isDaySanYuan = function () {
return this._isDayIn(TaoUtil.SAN_YUAN);
};
Tao.prototype.isDayBaJie = function () {
return TaoUtil.BA_JIE.containsKey(this._lunar.getJieQi());
};
Tao.prototype.isDayWuLa = function () {
return this._isDayIn(TaoUtil.WU_LA);
};
Tao.prototype.isDayBaHui = function () {
return TaoUtil.BA_HUI.containsKey(this._lunar.getDayInGanZhi());
};
Tao.prototype.isDayMingWu = function () {
return '戊' === this._lunar.getDayGan();
};
Tao.prototype.isDayAnWu = function () {
return this._lunar.getDayZhi() === TaoUtil.AN_WU[Math.abs(this.getMonth()) - 1];
};
Tao.prototype.isDayWu = function () {
return this.isDayMingWu() || this.isDayAnWu();
};
Tao.prototype.isDayTianShe = function () {
var ret = false;
var mz = this._lunar.getMonthZhi();
var dgz = this._lunar.getDayInGanZhi();
if ('寅卯辰'.indexOf(mz) > -1) {
if ('戊寅' === dgz) {
ret = true;
}
}
else if ('巳午未'.indexOf(mz) > -1) {
if ('甲午' === dgz) {
ret = true;
}
}
else if ('申酉戌'.indexOf(mz) > -1) {
if ('戊申' === dgz) {
ret = true;
}
}
else if ('亥子丑'.indexOf(mz) > -1) {
if ('甲子' === dgz) {
ret = true;
}
}
return ret;
};
Tao.prototype.toString = function () {
return this.getYearInChinese() + '年' + this.getMonthInChinese() + '月' + this.getDayInChinese();
};
Tao.prototype.toFullString = function () {
return '道歷' + this.getYearInChinese() + '年,天運' + this._lunar.getYearInGanZhi() + '年,' + this._lunar.getMonthInGanZhi() + '月,' + this._lunar.getDayInGanZhi() + '日。' + this.getMonthInChinese() + '月' + this.getDayInChinese() + '日,' + this._lunar.getTimeZhi() + '時。';
};
Tao.BIRTH_YEAR = -2697;
return Tao;
}());
export { Tao };
//# sourceMappingURL=Tao.js.map