lunar-lite
Version:
精简版的农历和阳历日期转换库。
42 lines (41 loc) • 1.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTotalDaysOfLunarMonth = exports.getZodiac = exports.getSign = void 0;
var lunar_typescript_1 = require("lunar-typescript");
var constants_1 = require("./constants");
var convertor_1 = require("./convertor");
/**
* 获取星座
*
* @param solarDateStr [description]
* @return 星座
*/
var getSign = function (solarDateStr) {
var _a = (0, convertor_1.normalizeDateStr)(solarDateStr), year = _a[0], month = _a[1], day = _a[2];
return lunar_typescript_1.Solar.fromYmd(year, month, day).getXingZuo() + "座";
};
exports.getSign = getSign;
/**
* 通过年支获取生肖
*
* @param earthlyBranchOfYear 年支
* @example
* const zodiac = calendar.getZodiac("卯") ;// zodiac='兔'
*/
var getZodiac = function (earthlyBranchOfYear) {
return constants_1.ZODIAC[constants_1.EARTHLY_BRANCHES.indexOf(earthlyBranchOfYear)];
};
exports.getZodiac = getZodiac;
/**
* 按照传入阳历日期获取该月农历月份天数
*
* @param solarDateStr 阳历日期
* @returns {number} 日期天数
*/
var getTotalDaysOfLunarMonth = function (solarDateStr) {
var _a;
var _b = (0, convertor_1.solar2lunar)(solarDateStr), lunarYear = _b.lunarYear, lunarMonth = _b.lunarMonth, isLeap = _b.isLeap;
var month = lunar_typescript_1.LunarMonth.fromYm(lunarYear, isLeap ? 0 - lunarMonth : lunarMonth);
return (_a = month === null || month === void 0 ? void 0 : month.getDayCount()) !== null && _a !== void 0 ? _a : 0;
};
exports.getTotalDaysOfLunarMonth = getTotalDaysOfLunarMonth;