UNPKG

@iro/calendar

Version:

lunar is a calendar library for Solar and Chinese Lunar.

133 lines 4.6 kB
import { Lunar } from './Lunar'; import { LunarUtil } from './LunarUtil'; import { FotoUtil } from './FotoUtil'; import { LunarMonth } from './LunarMonth'; var Foto = (function () { function Foto(lunar) { this._lunar = lunar; } Foto.fromLunar = function (lunar) { return new Foto(lunar); }; Foto.fromYmdHms = function (lunarYear, lunarMonth, lunarDay, hour, minute, second) { return Foto.fromLunar(Lunar.fromYmdHms(lunarYear + Foto.DEAD_YEAR - 1, lunarMonth, lunarDay, hour, minute, second)); }; Foto.fromYmd = function (lunarYear, lunarMonth, lunarDay) { return Foto.fromYmdHms(lunarYear, lunarMonth, lunarDay, 0, 0, 0); }; Foto.prototype.getLunar = function () { return this._lunar; }; Foto.prototype.getYear = function () { var sy = this._lunar.getSolar().getYear(); var y = sy - Foto.DEAD_YEAR; if (sy === this._lunar.getYear()) { y++; } return y; }; Foto.prototype.getMonth = function () { return this._lunar.getMonth(); }; Foto.prototype.getDay = function () { return this._lunar.getDay(); }; Foto.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; }; Foto.prototype.getMonthInChinese = function () { return this._lunar.getMonthInChinese(); }; Foto.prototype.getDayInChinese = function () { return this._lunar.getDayInChinese(); }; Foto.prototype.getFestivals = function () { var l = FotoUtil.FESTIVAL.get(this.getMonth() + '-' + this.getDay()); return l ? l : []; }; Foto.prototype.isMonthZhai = function () { var m = this.getMonth(); return 1 === m || 5 === m || 9 === m; }; Foto.prototype.isDayYangGong = function () { var l = this.getFestivals(); for (var i = 0, j = l.length; i < j; i++) { if ('杨公忌' === l[i].getName()) { return true; } } return false; }; Foto.prototype.isDayZhaiShuoWang = function () { var d = this.getDay(); return 1 === d || 15 === d; }; Foto.prototype.isDayZhaiSix = function () { var d = this.getDay(); if (8 === d || 14 === d || 15 === d || 23 === d || 29 === d || 30 === d) { return true; } else if (28 === d) { var m = LunarMonth.fromYm(this._lunar.getYear(), this.getMonth()); if (null != m && 30 !== m.getDayCount()) { return true; } } return false; }; Foto.prototype.isDayZhaiTen = function () { var d = this.getDay(); return 1 === d || 8 === d || 14 === d || 15 === d || 18 === d || 23 === d || 24 === d || 28 === d || 29 === d || 30 === d; }; Foto.prototype.isDayZhaiGuanYin = function () { var k = this.getMonth() + '-' + this.getDay(); for (var i = 0, j = FotoUtil.DAY_ZHAI_GUAN_YIN.length; i < j; i++) { if (k === FotoUtil.DAY_ZHAI_GUAN_YIN[i]) { return true; } } return false; }; Foto.prototype.getXiu = function () { return FotoUtil.getXiu(this.getMonth(), this.getDay()); }; Foto.prototype.getXiuLuck = function () { return LunarUtil.XIU_LUCK.get(this.getXiu()); }; Foto.prototype.getXiuSong = function () { return LunarUtil.XIU_SONG.get(this.getXiu()); }; Foto.prototype.getZheng = function () { return LunarUtil.ZHENG.get(this.getXiu()); }; Foto.prototype.getAnimal = function () { return LunarUtil.ANIMAL.get(this.getXiu()); }; Foto.prototype.getGong = function () { return LunarUtil.GONG.get(this.getXiu()); }; Foto.prototype.getShou = function () { return LunarUtil.SHOU.get(this.getGong()); }; Foto.prototype.toString = function () { return this.getYearInChinese() + '年' + this.getMonthInChinese() + '月' + this.getDayInChinese(); }; Foto.prototype.toFullString = function () { var s = this.toString(); var festivals = this.getFestivals(); for (var i = 0, j = festivals.length; i < j; i++) { s += ' (' + festivals[i] + ')'; } return s; }; Foto.DEAD_YEAR = -543; return Foto; }()); export { Foto }; //# sourceMappingURL=Foto.js.map