lunar-calendar-plus
Version:
lunar-calendar-plus是一个可自定义设置假期、节日;获取指定农历日期、节气、每日宜忌、天文历等灵活的js库。支持Typescript!
67 lines (58 loc) • 1.51 kB
JavaScript
/*
* @Description:
* @version:
* @Author: XJ
* @Date: 2021-01-12 16:23:56
*/
;
var lunarCode = require("../config/lunarCode");
function lunarYear() {}
/**
* 闰月、闰月天数
* @param {*} year
* @returns {leap,day}
*/
lunarYear.prototype.getLeapMonth = function (year = "") {
var isLeap = lunarCode[year - 1900] & 0xf;
var returnObj = {};
if (isLeap == 0xf || !isLeap) {
returnObj["isLeap"] = false;
returnObj["leapMonth"] = -1;
returnObj["day"] = 0;
} else {
returnObj["isLeap"] = true;
returnObj["leapMonth"] = isLeap;
returnObj["day"] = (lunarCode[year - 1899] & 0xf) == 0xf ? 30 : 29;
}
return returnObj;
};
/**
* 返回指定阴历月份的天数
* @param {*} y
* @param {*} m
*/
lunarYear.prototype.getMonthDay = function (y = "", m = "") {
return lunarCode[y - 1900] & (0x10000 >> m) ? 30 : 29;
};
/**
* 指定年的天数(不包括闰月)
* @param {*} year
*/
lunarYear.prototype.yearDay = function (year) {
/**
* 阴历年,大月30天、小月29天。
* 以348为基准可以算出指定阴历年的天数,包括闰月存在的情况
*/
var baseDay = 348;
/**
* 通过和指定二进制比较月份,
* [二进制中间十二位,0为小月,1为大月]
*/
var baseB = 0x8000;
while (baseB > 0x8) {
baseDay += lunarCode[year - 1900] & baseB ? 1 : 0;
baseB >>= 1;
}
return baseDay;
};
module.exports = lunarYear;