UNPKG

iztro

Version:

轻量级紫微斗数星盘生成库。可以通过出生年月日获取到紫微斗数星盘信息、生肖、星座等信息。This is a lightweight kit for generating astrolabes for Zi Wei Dou Shu (The Purple Star Astrology), an ancient Chinese astrology. It allows you to obtain your horoscope and personality analysis.

58 lines (57 loc) 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTotalDaysOfSolarMonth = exports.getTotalDaysOfLunarMonth = exports.getTotalDaysOfLunarYear = void 0; var leap_1 = require("./leap"); var rules_1 = require("./rules"); /** * 返回农历年一整年的总天数 * * @param year 农历年份 * @return number * @example * count = getTotalDaysOfLunarYear(1987) ;//count=387 */ var getTotalDaysOfLunarYear = function (year) { var sum = 348; for (var i = 0x8000; i > 0x8; i >>= 1) { sum += rules_1.LUNAR_INFO[year - 1900] & i ? 1 : 0; } return sum + (0, leap_1.getLeapDays)(year); }; exports.getTotalDaysOfLunarYear = getTotalDaysOfLunarYear; /** * 返回农历月(非闰月)的总天数,计算闰月时的天数请使用getLeapDays方法 * * @param year 农历年份 * @param month 农历月份,取值【1~12】 * @return 29 | 30 * @example * MonthDay = getTotalDaysOfLunarMonth(1987,9) ;//MonthDay=29 */ var getTotalDaysOfLunarMonth = function (year, month) { if (month > 12 || month < 1) { throw new Error('invalid month.'); } return rules_1.LUNAR_INFO[year - 1900] & (0x10000 >> month) ? 30 : 29; }; exports.getTotalDaysOfLunarMonth = getTotalDaysOfLunarMonth; /** * 返回公历月的天数 * * @param year 公历年 * @param month 公历月,取值【1~12】,若参数错误 返回-1 * @return 28 | 29 | 30 | 31 * @example * solarMonthDay = getTotalDaysOfSolarMonth(1987, 1) ; // solarMonthDay=30 */ var getTotalDaysOfSolarMonth = function (year, month) { if (month > 12 || month < 1) { throw new Error('invalid month.'); } if (month === 2) { // 2月份的闰平规律测算后确认返回28或29 return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0 ? 29 : 28; } return rules_1.SOLAR_MONTH[month - 1]; }; exports.getTotalDaysOfSolarMonth = getTotalDaysOfSolarMonth;