|
|
|
@ -1,190 +1,6 @@
|
|
|
|
|
/** unfetch */
|
|
|
|
|
self.fetch||(self.fetch=function(e,n){return n=n||{},new Promise(function(t,s){var r=new XMLHttpRequest,o=[],u=[],i={},a=function(){return{ok:2==(r.status/100|0),statusText:r.statusText,status:r.status,url:r.responseURL,text:function(){return Promise.resolve(r.responseText)},json:function(){return Promise.resolve(JSON.parse(r.responseText))},blob:function(){return Promise.resolve(new Blob([r.response]))},clone:a,headers:{keys:function(){return o},entries:function(){return u},get:function(e){return i[e.toLowerCase()]},has:function(e){return e.toLowerCase()in i}}}};for(var c in r.open(n.method||"get",e,!0),r.onload=function(){r.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,n,t){o.push(n=n.toLowerCase()),u.push([n,t]),i[n]=i[n]?i[n]+","+t:t}),t(a())},r.onerror=s,r.withCredentials="include"==n.credentials,n.headers)r.setRequestHeader(c,n.headers[c]);r.send(n.body||null)})});
|
|
|
|
|
|
|
|
|
|
var LunarDate = {
|
|
|
|
|
madd: new Array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334),
|
|
|
|
|
HsString: '甲乙丙丁戊己庚辛壬癸',
|
|
|
|
|
EbString: '子丑寅卯辰巳午未申酉戌亥',
|
|
|
|
|
NumString: "一二三四五六七八九十",
|
|
|
|
|
MonString: "正二三四五六七八九十冬腊",
|
|
|
|
|
CalendarData: new Array(0xA4B, 0x5164B, 0x6A5, 0x6D4, 0x415B5, 0x2B6, 0x957, 0x2092F, 0x497, 0x60C96, 0xD4A, 0xEA5, 0x50DA9, 0x5AD, 0x2B6, 0x3126E, 0x92E, 0x7192D, 0xC95, 0xD4A, 0x61B4A, 0xB55, 0x56A, 0x4155B, 0x25D, 0x92D, 0x2192B, 0xA95, 0x71695, 0x6CA, 0xB55, 0x50AB5, 0x4DA, 0xA5B, 0x30A57, 0x52B, 0x8152A, 0xE95, 0x6AA, 0x615AA, 0xAB5, 0x4B6, 0x414AE, 0xA57, 0x526, 0x31D26, 0xD95, 0x70B55, 0x56A, 0x96D, 0x5095D, 0x4AD, 0xA4D, 0x41A4D, 0xD25, 0x81AA5, 0xB54, 0xB6A, 0x612DA, 0x95B, 0x49B, 0x41497, 0xA4B, 0xA164B, 0x6A5, 0x6D4, 0x615B4, 0xAB6, 0x957, 0x5092F, 0x497, 0x64B, 0x30D4A, 0xEA5, 0x80D65, 0x5AC, 0xAB6, 0x5126D, 0x92E, 0xC96, 0x41A95, 0xD4A, 0xDA5, 0x20B55, 0x56A, 0x7155B, 0x25D, 0x92D, 0x5192B, 0xA95, 0xB4A, 0x416AA, 0xAD5, 0x90AB5, 0x4BA, 0xA5B, 0x60A57, 0x52B, 0xA93, 0x40E95),
|
|
|
|
|
Year: null,
|
|
|
|
|
Month: null,
|
|
|
|
|
Day: null,
|
|
|
|
|
TheDate: null,
|
|
|
|
|
GetBit: function(m, n) {
|
|
|
|
|
return (m >> n) & 1;
|
|
|
|
|
},
|
|
|
|
|
e2c: function() {
|
|
|
|
|
this.TheDate = (arguments.length != 3) ? new Date() : new Date(arguments[0], arguments[1], arguments[2]);
|
|
|
|
|
var total, m, n, k;
|
|
|
|
|
var isEnd = false;
|
|
|
|
|
var tmp = this.TheDate.getFullYear();
|
|
|
|
|
total = (tmp - 1921) * 365 + Math.floor((tmp - 1921) / 4) + this.madd[this.TheDate.getMonth()] + this.TheDate.getDate() - 38;
|
|
|
|
|
if (this.TheDate.getYear() % 4 == 0 && this.TheDate.getMonth() > 1) {
|
|
|
|
|
total++;
|
|
|
|
|
}
|
|
|
|
|
for (m = 0;; m++) {
|
|
|
|
|
k = (this.CalendarData[m] < 0xfff) ? 11 : 12;
|
|
|
|
|
for (n = k; n >= 0; n--) {
|
|
|
|
|
if (total <= 29 + this.GetBit(this.CalendarData[m], n)) {
|
|
|
|
|
isEnd = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
total = total - 29 - this.GetBit(this.CalendarData[m], n);
|
|
|
|
|
}
|
|
|
|
|
if (isEnd)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
this.Year = 1921 + m;
|
|
|
|
|
this.Month = k - n + 1;
|
|
|
|
|
this.Day = total;
|
|
|
|
|
if (k == 12) {
|
|
|
|
|
if (this.Month == Math.floor(this.CalendarData[m] / 0x10000) + 1) {
|
|
|
|
|
this.Month = 1 - this.Month;
|
|
|
|
|
}
|
|
|
|
|
if (this.Month > Math.floor(this.CalendarData[m] / 0x10000) + 1) {
|
|
|
|
|
this.Month--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
GetcDateString: function() {
|
|
|
|
|
var tmp = "";
|
|
|
|
|
tmp += this.HsString.charAt((this.Year - 4) % 10);
|
|
|
|
|
tmp += this.EbString.charAt((this.Year - 4) % 12);
|
|
|
|
|
tmp += "年 ";
|
|
|
|
|
if (this.Month < 1) {
|
|
|
|
|
tmp += "(闰)";
|
|
|
|
|
tmp += this.MonString.charAt(-this.Month - 1);
|
|
|
|
|
} else {
|
|
|
|
|
tmp += this.MonString.charAt(this.Month - 1);
|
|
|
|
|
}
|
|
|
|
|
tmp += "月";
|
|
|
|
|
tmp += (this.Day < 11) ? "初" : ((this.Day < 20) ? "十" : ((this.Day < 30) ? "廿" : "三十"));
|
|
|
|
|
if (this.Day % 10 != 0 || this.Day == 10) {
|
|
|
|
|
tmp += this.NumString.charAt((this.Day - 1) % 10);
|
|
|
|
|
}
|
|
|
|
|
return tmp;
|
|
|
|
|
},
|
|
|
|
|
GetLunarDay: function(solarYear, solarMonth, solarDay) {
|
|
|
|
|
if (solarYear < 1921 || solarYear > 2020) {
|
|
|
|
|
return "";
|
|
|
|
|
} else {
|
|
|
|
|
solarMonth = (parseInt(solarMonth) > 0) ? (solarMonth - 1) : 11;
|
|
|
|
|
this.e2c(solarYear, solarMonth, solarDay);
|
|
|
|
|
return this.GetcDateString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var rat = {
|
|
|
|
|
name: "Rat",
|
|
|
|
|
luckyColors: "blue, gold, green",
|
|
|
|
|
luckyNumbers: "2, 3",
|
|
|
|
|
work: "/pic/star/five-stars.png",
|
|
|
|
|
wealth: "/pic/star/five-stars.png",
|
|
|
|
|
love: "/pic/star/four-stars.png",
|
|
|
|
|
health: "/pic/star/three-stars.png"
|
|
|
|
|
};
|
|
|
|
|
var ox = {
|
|
|
|
|
name: "Ox",
|
|
|
|
|
luckyColors: "blue, yellow, green",
|
|
|
|
|
luckyNumbers: "1, 4",
|
|
|
|
|
work: "/pic/star/three-stars.png",
|
|
|
|
|
wealth: "/pic/star/two-stars.png",
|
|
|
|
|
love: "/pic/star/three-stars.png",
|
|
|
|
|
health: "/pic/star/two-stars.png"
|
|
|
|
|
};
|
|
|
|
|
var tiger = {
|
|
|
|
|
name: "Tiger",
|
|
|
|
|
luckyColors: "blue, grey, white, orange",
|
|
|
|
|
luckyNumbers: "1, 3, 4",
|
|
|
|
|
work: "/pic/star/four-stars.png",
|
|
|
|
|
wealth: "/pic/star/three-stars.png",
|
|
|
|
|
love: "/pic/star/four-stars.png",
|
|
|
|
|
health: "/pic/star/three-stars.png"
|
|
|
|
|
};
|
|
|
|
|
var rabbit = {
|
|
|
|
|
name: "Rabbit",
|
|
|
|
|
luckyColors: "red, pink, purple, blue",
|
|
|
|
|
luckyNumbers: "3, 4, 9",
|
|
|
|
|
work: "/pic/star/four-stars.png",
|
|
|
|
|
wealth: "/pic/star/three-stars.png",
|
|
|
|
|
love: "/pic/star/three-stars.png",
|
|
|
|
|
health: "/pic/star/three-stars.png"
|
|
|
|
|
};
|
|
|
|
|
var dragon = {
|
|
|
|
|
name: "Dragon",
|
|
|
|
|
luckyColors: "gold, silver, grayish white",
|
|
|
|
|
luckyNumbers: "1, 6, 7",
|
|
|
|
|
work: "/pic/star/two-stars.png",
|
|
|
|
|
wealth: "/pic/star/two-stars.png",
|
|
|
|
|
love: "/pic/star/three-stars.png",
|
|
|
|
|
health: "/pic/star/two-stars.png"
|
|
|
|
|
};
|
|
|
|
|
var snake = {
|
|
|
|
|
name: "Snake",
|
|
|
|
|
luckyColors: "red, pale yellow, black",
|
|
|
|
|
luckyNumbers: "2, 8, 9",
|
|
|
|
|
work: "/pic/star/four-stars.png",
|
|
|
|
|
wealth: "/pic/star/four-stars.png",
|
|
|
|
|
love: "/pic/star/three-stars.png",
|
|
|
|
|
health: "/pic/star/two-stars.png"
|
|
|
|
|
};
|
|
|
|
|
var horse = {
|
|
|
|
|
name: "Horse",
|
|
|
|
|
luckyColors: "green, red, purple",
|
|
|
|
|
luckyNumbers: "3, 4, 9",
|
|
|
|
|
work: "/pic/star/four-stars.png",
|
|
|
|
|
wealth: "/pic/star/three-stars.png",
|
|
|
|
|
love: "/pic/star/two-stars.png",
|
|
|
|
|
health: "/pic/star/two-stars.png"
|
|
|
|
|
};
|
|
|
|
|
var goat = {
|
|
|
|
|
name: "Goat",
|
|
|
|
|
luckyColors: "brown, red, purple",
|
|
|
|
|
luckyNumbers: "2, 7",
|
|
|
|
|
work: "/pic/star/two-stars.png",
|
|
|
|
|
wealth: "/pic/star/two-stars.png",
|
|
|
|
|
love: "/pic/star/two-stars.png",
|
|
|
|
|
health: "/pic/star/four-stars.png"
|
|
|
|
|
};
|
|
|
|
|
var monkey = {
|
|
|
|
|
name: "Monkey",
|
|
|
|
|
luckyColors: "white, gold, blue",
|
|
|
|
|
luckyNumbers: "1, 7, 8",
|
|
|
|
|
work: "/pic/star/five-stars.png",
|
|
|
|
|
wealth: "/pic/star/three-stars.png",
|
|
|
|
|
love: "/pic/star/four-stars.png",
|
|
|
|
|
health: "/pic/star/two-stars.png"
|
|
|
|
|
};
|
|
|
|
|
var rooster = {
|
|
|
|
|
name: "Rooster",
|
|
|
|
|
luckyColors: "gold, brown, yellow",
|
|
|
|
|
luckyNumbers: "5, 7, 8",
|
|
|
|
|
work: "/pic/star/five-stars.png",
|
|
|
|
|
wealth: "/pic/star/four-stars.png",
|
|
|
|
|
love: "/pic/star/four-stars.png",
|
|
|
|
|
health: "/pic/star/three-stars.png"
|
|
|
|
|
};
|
|
|
|
|
var dog = {
|
|
|
|
|
name: "Dog",
|
|
|
|
|
luckyColors: "green, red, purple",
|
|
|
|
|
luckyNumbers: "3,4,9",
|
|
|
|
|
work: "/pic/star/four-stars.png",
|
|
|
|
|
wealth: "/pic/star/three-stars.png",
|
|
|
|
|
love: "/pic/star/three-stars.png",
|
|
|
|
|
health: "/pic/star/two-stars.png"
|
|
|
|
|
};
|
|
|
|
|
var pig = {
|
|
|
|
|
name: "Pig",
|
|
|
|
|
luckyColors: "yellow, gray, brown, gold",
|
|
|
|
|
luckyNumbers: "2, 5, 8",
|
|
|
|
|
work: "/pic/star/four-stars.png",
|
|
|
|
|
wealth: "/pic/star/three-stars.png",
|
|
|
|
|
love: "/pic/star/four-stars.png",
|
|
|
|
|
health: "/pic/star/three-stars.png"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function dozodiacsearch() {
|
|
|
|
|
var year = document.getElementById('yr').value;
|
|
|
|
@ -194,14 +10,12 @@ function dozodiacsearch() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LunarDate.GetLunarDay(year, month, day);
|
|
|
|
|
var lunarYear = LunarDate.Year;
|
|
|
|
|
var c_data = calendar.solar2lunar(year,month,day); //计算农历
|
|
|
|
|
console.log(c_data);
|
|
|
|
|
var lunarYear = c_data.lYear;
|
|
|
|
|
|
|
|
|
|
//通过获取到的年份信息进行生肖的计算
|
|
|
|
|
//获取到的年份-1900的基数,与12求余
|
|
|
|
|
//通过获得的农历年份-1900的基数,与12求余确定生肖数组中的位置
|
|
|
|
|
var remainder = (lunarYear - 1900) % 12;
|
|
|
|
|
//根据求余的数确定生肖
|
|
|
|
|
//直接读取数据库数据,2021-12-10 zp
|
|
|
|
|
//直接读取前台生成的生肖JSON数据,减少服务器压力。 2022-3-1 zp
|
|
|
|
|
var dataurl = "https://www.chinahighlights.com/createjs/zodiac-data.js?temp=1";
|
|
|
|
|
//var dataurl = "https://www.chinahighlights.com/guide-use.php/travelguide/getzodiac/";
|
|
|
|
@ -228,27 +42,394 @@ function dozodiacsearch() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// zodiacList = [
|
|
|
|
|
// rat, ox, tiger, rabbit, dragon, snake,
|
|
|
|
|
// horse, goat, monkey, rooster, dog, pig
|
|
|
|
|
// ];
|
|
|
|
|
// var zodiac = zodiacList[remainder];
|
|
|
|
|
// document.getElementById('zodiacYear').innerText = 'Your Luck in 2021';
|
|
|
|
|
// document.getElementById('zodiacName').innerText = zodiac.name;
|
|
|
|
|
// document.getElementById('zodiacLuckyNumbers').innerText = zodiac.luckyNumbers;
|
|
|
|
|
// document.getElementById('zodiacLuckyColors').innerText = zodiac.luckyColors;
|
|
|
|
|
|
|
|
|
|
// document.getElementById('zodiacWork').setAttribute("src", zodiac.work);
|
|
|
|
|
// document.getElementById('zodiacWealth').setAttribute("src", zodiac.wealth);
|
|
|
|
|
// document.getElementById('zodiacLove').setAttribute("src", zodiac.love);
|
|
|
|
|
// document.getElementById('zodiacHealth').setAttribute("src", zodiac.health);
|
|
|
|
|
|
|
|
|
|
// var zodiacLink = document.getElementById('zodiacHealth');
|
|
|
|
|
// zodiacLink.setAttribute(
|
|
|
|
|
// "href",
|
|
|
|
|
// "//www.chinahighlights.com/travelguide/chinese-zodiac/" +
|
|
|
|
|
// zodiac.name.toLowerCase() + ".htm");
|
|
|
|
|
// zodiacLink.innerText = 'More about zodiac "' + zodiac.name + '"';
|
|
|
|
|
// document.getElementById('idzodiac').style.display = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @1900-2100区间内的公历转农历
|
|
|
|
|
* @charset UTF-8
|
|
|
|
|
* @Version 1.0 2022-3-2 zp
|
|
|
|
|
* @公历转农历:calendar.solar2lunar(1987,11,01);
|
|
|
|
|
*/
|
|
|
|
|
const calendar = {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 农历1900-2100的润大小信息表
|
|
|
|
|
* @Array Of Property
|
|
|
|
|
* @return Hex
|
|
|
|
|
*/
|
|
|
|
|
lunarInfo: [0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2,//1900-1909
|
|
|
|
|
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977,//1910-1919
|
|
|
|
|
0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970,//1920-1929
|
|
|
|
|
0x06566, 0x0d4a0, 0x0ea50, 0x16a95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950,//1930-1939
|
|
|
|
|
0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557,//1940-1949
|
|
|
|
|
0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5b0, 0x14573, 0x052b0, 0x0a9a8, 0x0e950, 0x06aa0,//1950-1959
|
|
|
|
|
0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0,//1960-1969
|
|
|
|
|
0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b6a0, 0x195a6,//1970-1979
|
|
|
|
|
0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570,//1980-1989
|
|
|
|
|
0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x05ac0, 0x0ab60, 0x096d5, 0x092e0,//1990-1999
|
|
|
|
|
0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5,//2000-2009
|
|
|
|
|
0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930,//2010-2019
|
|
|
|
|
0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530,//2020-2029
|
|
|
|
|
0x05aa0, 0x076a3, 0x096d0, 0x04afb, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45,//2030-2039
|
|
|
|
|
0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0,//2040-2049
|
|
|
|
|
0x14b63, 0x09370, 0x049f8, 0x04970, 0x064b0, 0x168a6, 0x0ea50, 0x06b20, 0x1a6c4, 0x0aae0,//2050-2059
|
|
|
|
|
0x092e0, 0x0d2e3, 0x0c960, 0x0d557, 0x0d4a0, 0x0da50, 0x05d55, 0x056a0, 0x0a6d0, 0x055d4,//2060-2069
|
|
|
|
|
0x052d0, 0x0a9b8, 0x0a950, 0x0b4a0, 0x0b6a6, 0x0ad50, 0x055a0, 0x0aba4, 0x0a5b0, 0x052b0,//2070-2079
|
|
|
|
|
0x0b273, 0x06930, 0x07337, 0x06aa0, 0x0ad50, 0x14b55, 0x04b60, 0x0a570, 0x054e4, 0x0d160,//2080-2089
|
|
|
|
|
0x0e968, 0x0d520, 0x0daa0, 0x16aa6, 0x056d0, 0x04ae0, 0x0a9d4, 0x0a2d0, 0x0d150, 0x0f252,//2090-2099
|
|
|
|
|
0x0d520],//2100
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 公历每个月份的天数普通表
|
|
|
|
|
* @Array Of Property
|
|
|
|
|
* @return Number
|
|
|
|
|
*/
|
|
|
|
|
solarMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 天干地支之天干速查表
|
|
|
|
|
* @Array Of Property trans["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"]
|
|
|
|
|
* @return Cn string
|
|
|
|
|
*/
|
|
|
|
|
Gan: ["\u7532", "\u4e59", "\u4e19", "\u4e01", "\u620a", "\u5df1", "\u5e9a", "\u8f9b", "\u58ec", "\u7678"],
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 天干地支之地支速查表
|
|
|
|
|
* @Array Of Property
|
|
|
|
|
* @trans["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"]
|
|
|
|
|
* @return Cn string
|
|
|
|
|
*/
|
|
|
|
|
Zhi: ["\u5b50", "\u4e11", "\u5bc5", "\u536f", "\u8fb0", "\u5df3", "\u5348", "\u672a", "\u7533", "\u9149", "\u620c", "\u4ea5"],
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 天干地支之地支速查表<=>生肖
|
|
|
|
|
* @Array Of Property
|
|
|
|
|
* @trans["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"]
|
|
|
|
|
* @return Cn string
|
|
|
|
|
*/
|
|
|
|
|
Animals: ["\u9f20", "\u725b", "\u864e", "\u5154", "\u9f99", "\u86c7", "\u9a6c", "\u7f8a", "\u7334", "\u9e21", "\u72d7", "\u732a"],
|
|
|
|
|
Zodiac: ["Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Goat","Monkey","Rooster","Dog","Pig"],
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 农历节日
|
|
|
|
|
*/
|
|
|
|
|
lFestival: {
|
|
|
|
|
'12-30': {title: '除夕'},
|
|
|
|
|
'1-1': {title: '春节'},
|
|
|
|
|
'1-15': {title: '元宵节'},
|
|
|
|
|
'2-2': {title: '龙抬头'},
|
|
|
|
|
'5-5': {title: '端午节'},
|
|
|
|
|
'7-7': {title: '七夕节'},
|
|
|
|
|
'7-15': {title: '中元节'},
|
|
|
|
|
'8-15': {title: '中秋节'},
|
|
|
|
|
'9-9': {title: '重阳节'},
|
|
|
|
|
'10-1': {title: '寒衣节'},
|
|
|
|
|
'10-15': {title: '下元节'},
|
|
|
|
|
'12-8': {title: '腊八节'},
|
|
|
|
|
'12-23': {title: '北方小年'},
|
|
|
|
|
'12-24': {title: '南方小年'},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回默认定义的内容里节日
|
|
|
|
|
*/
|
|
|
|
|
getLunarFestival() {
|
|
|
|
|
return this.lFestival
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param param {Object} 按照lFestival的格式输入数据,设置农历节日
|
|
|
|
|
*/
|
|
|
|
|
setLunarFestival(param = {}) {
|
|
|
|
|
this.lFestival = param
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数字转中文速查表
|
|
|
|
|
* @Array Of Property
|
|
|
|
|
* @trans ['日','一','二','三','四','五','六','七','八','九','十']
|
|
|
|
|
* @return Cn string
|
|
|
|
|
*/
|
|
|
|
|
nStr1: ["\u65e5", "\u4e00", "\u4e8c", "\u4e09", "\u56db", "\u4e94", "\u516d", "\u4e03", "\u516b", "\u4e5d", "\u5341"],
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 日期转农历称呼速查表
|
|
|
|
|
* @Array Of Property
|
|
|
|
|
* @trans ['初','十','廿','卅']
|
|
|
|
|
* @return Cn string
|
|
|
|
|
*/
|
|
|
|
|
nStr2: ["\u521d", "\u5341", "\u5eff", "\u5345"],
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 月份转农历称呼速查表
|
|
|
|
|
* @Array Of Property
|
|
|
|
|
* @trans ['正','一','二','三','四','五','六','七','八','九','十','冬','腊']
|
|
|
|
|
* @return Cn string
|
|
|
|
|
*/
|
|
|
|
|
nStr3: ["\u6b63", "\u4e8c", "\u4e09", "\u56db", "\u4e94", "\u516d", "\u4e03", "\u516b", "\u4e5d", "\u5341", "\u51ac", "\u814a"],
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回农历y年一整年的总天数
|
|
|
|
|
* @param y lunar Year
|
|
|
|
|
* @return Number
|
|
|
|
|
* @eg:var count = calendar.lYearDays(1987) ;//count=387
|
|
|
|
|
*/
|
|
|
|
|
lYearDays: function (y) {
|
|
|
|
|
let i, sum = 348;
|
|
|
|
|
for (i = 0x8000; i > 0x8; i >>= 1) {
|
|
|
|
|
sum += (this.lunarInfo[y - 1900] & i) ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
return (sum + this.leapDays(y));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回农历y年闰月是哪个月;若y年没有闰月 则返回0
|
|
|
|
|
* @param y lunar Year
|
|
|
|
|
* @return Number (0-12)
|
|
|
|
|
* @eg:var leapMonth = calendar.leapMonth(1987) ;//leapMonth=6
|
|
|
|
|
*/
|
|
|
|
|
leapMonth: function (y) { //闰字编码 \u95f0
|
|
|
|
|
return (this.lunarInfo[y - 1900] & 0xf);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回农历y年闰月的天数 若该年没有闰月则返回0
|
|
|
|
|
* @param y lunar Year
|
|
|
|
|
* @return Number (0、29、30)
|
|
|
|
|
* @eg:var leapMonthDay = calendar.leapDays(1987) ;//leapMonthDay=29
|
|
|
|
|
*/
|
|
|
|
|
leapDays: function (y) {
|
|
|
|
|
if (this.leapMonth(y)) {
|
|
|
|
|
return ((this.lunarInfo[y - 1900] & 0x10000) ? 30 : 29);
|
|
|
|
|
}
|
|
|
|
|
return (0);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回农历y年m月(非闰月)的总天数,计算m为闰月时的天数请使用leapDays方法
|
|
|
|
|
* @param y lunar Year
|
|
|
|
|
* @param m lunar Month
|
|
|
|
|
* @return Number (-1、29、30)
|
|
|
|
|
* @eg:var MonthDay = calendar.monthDays(1987,9) ;//MonthDay=29
|
|
|
|
|
*/
|
|
|
|
|
monthDays: function (y, m) {
|
|
|
|
|
if (m > 12 || m < 1) {
|
|
|
|
|
return -1
|
|
|
|
|
}//月份参数从1至12,参数错误返回-1
|
|
|
|
|
return ((this.lunarInfo[y - 1900] & (0x10000 >> m)) ? 30 : 29);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回公历(!)y年m月的天数
|
|
|
|
|
* @param y solar Year
|
|
|
|
|
* @param m solar Month
|
|
|
|
|
* @return Number (-1、28、29、30、31)
|
|
|
|
|
* @eg:var solarMonthDay = calendar.leapDays(1987) ;//solarMonthDay=30
|
|
|
|
|
*/
|
|
|
|
|
solarDays: function (y, m) {
|
|
|
|
|
if (m > 12 || m < 1) {
|
|
|
|
|
return -1
|
|
|
|
|
} //若参数错误 返回-1
|
|
|
|
|
const ms = m - 1;
|
|
|
|
|
if (ms === 1) { //2月份的闰平规律测算后确认返回28或29
|
|
|
|
|
return (((y % 4 === 0) && (y % 100 !== 0) || (y % 400 === 0)) ? 29 : 28);
|
|
|
|
|
} else {
|
|
|
|
|
return (this.solarMonth[ms]);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 传入农历数字月份返回汉语通俗表示法
|
|
|
|
|
* @param m lunar month
|
|
|
|
|
* @return Cn string
|
|
|
|
|
* @eg:var cnMonth = calendar.toChinaMonth(12) ;//cnMonth='腊月'
|
|
|
|
|
*/
|
|
|
|
|
toChinaMonth: function (m) { // 月 => \u6708
|
|
|
|
|
if (m > 12 || m < 1) {
|
|
|
|
|
return -1
|
|
|
|
|
} //若参数错误 返回-1
|
|
|
|
|
let s = this.nStr3[m - 1];
|
|
|
|
|
s += "\u6708";//加上月字
|
|
|
|
|
return s;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 传入农历日期数字返回汉字表示法
|
|
|
|
|
* @param d lunar day
|
|
|
|
|
* @return Cn string
|
|
|
|
|
* @eg:var cnDay = calendar.toChinaDay(21) ;//cnMonth='廿一'
|
|
|
|
|
*/
|
|
|
|
|
toChinaDay: function (d) { //日 => \u65e5
|
|
|
|
|
let s;
|
|
|
|
|
switch (d) {
|
|
|
|
|
case 10:
|
|
|
|
|
s = '\u521d\u5341';
|
|
|
|
|
break;
|
|
|
|
|
case 20:
|
|
|
|
|
s = '\u4e8c\u5341';
|
|
|
|
|
break;
|
|
|
|
|
case 30:
|
|
|
|
|
s = '\u4e09\u5341';
|
|
|
|
|
break;
|
|
|
|
|
default :
|
|
|
|
|
s = this.nStr2[Math.floor(d / 10)];
|
|
|
|
|
s += this.nStr1[d % 10];
|
|
|
|
|
}
|
|
|
|
|
return (s);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 年份转生肖[!仅能大致转换] => 精确划分生肖分界线是“立春”
|
|
|
|
|
* @param y year
|
|
|
|
|
* @return Cn string
|
|
|
|
|
* @eg:var animal = calendar.getAnimal(1987) ;//animal='兔'
|
|
|
|
|
*/
|
|
|
|
|
getAnimal: function (y) {
|
|
|
|
|
return this.Animals[(y - 4) % 12]
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getZodiac :function (y){
|
|
|
|
|
return this.Zodiac[(y-4) % 12]
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 传入阳历年月日获得详细的公历、农历object信息 <=>JSON
|
|
|
|
|
* !important! 公历参数区间1900.1.31~2100.12.31
|
|
|
|
|
* @param yPara solar year
|
|
|
|
|
* @param mPara solar month
|
|
|
|
|
* @param dPara solar day
|
|
|
|
|
* @return JSON object
|
|
|
|
|
* @eg:console.log(calendar.solar2lunar(1987,11,01));
|
|
|
|
|
*/
|
|
|
|
|
solar2lunar: function (yPara, mPara, dPara) {
|
|
|
|
|
let y = parseInt(yPara);
|
|
|
|
|
let m = parseInt(mPara);
|
|
|
|
|
let d = parseInt(dPara);
|
|
|
|
|
//年份限定、上限
|
|
|
|
|
if (y < 1900 || y > 2100) {
|
|
|
|
|
return -1;// undefined转换为数字变为NaN
|
|
|
|
|
}
|
|
|
|
|
//公历传参最下限
|
|
|
|
|
if (y === 1900 && m === 1 && d < 31) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//未传参 获得当天
|
|
|
|
|
let objDate;
|
|
|
|
|
if (!y) {
|
|
|
|
|
objDate = new Date();
|
|
|
|
|
} else {
|
|
|
|
|
objDate = new Date(y, parseInt(m) - 1, d);
|
|
|
|
|
}
|
|
|
|
|
let i, leap = 0, temp = 0;
|
|
|
|
|
//修正ymd参数
|
|
|
|
|
y = objDate.getFullYear();
|
|
|
|
|
m = objDate.getMonth() + 1;
|
|
|
|
|
d = objDate.getDate();
|
|
|
|
|
let offset = (Date.UTC(objDate.getFullYear(), objDate.getMonth(), objDate.getDate()) - Date.UTC(1900, 0, 31)) / 86400000;
|
|
|
|
|
for (i = 1900; i < 2101 && offset > 0; i++) {
|
|
|
|
|
temp = this.lYearDays(i);
|
|
|
|
|
offset -= temp;
|
|
|
|
|
}
|
|
|
|
|
if (offset < 0) {
|
|
|
|
|
offset += temp;
|
|
|
|
|
i--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//是否今天
|
|
|
|
|
let isTodayObj = new Date(),
|
|
|
|
|
isToday = false;
|
|
|
|
|
if (isTodayObj.getFullYear() === y && isTodayObj.getMonth() + 1 === m && isTodayObj.getDate() === d) {
|
|
|
|
|
isToday = true;
|
|
|
|
|
}
|
|
|
|
|
//星期几
|
|
|
|
|
let nWeek = objDate.getDay(),
|
|
|
|
|
cWeek = this.nStr1[nWeek];
|
|
|
|
|
//数字表示周几顺应天朝周一开始的惯例
|
|
|
|
|
if (nWeek === 0) {
|
|
|
|
|
nWeek = 7;
|
|
|
|
|
}
|
|
|
|
|
//农历年
|
|
|
|
|
const year = i;
|
|
|
|
|
leap = this.leapMonth(i); //闰哪个月
|
|
|
|
|
let isLeap = false;
|
|
|
|
|
|
|
|
|
|
//效验闰月
|
|
|
|
|
for (i = 1; i < 13 && offset > 0; i++) {
|
|
|
|
|
//闰月
|
|
|
|
|
if (leap > 0 && i === (leap + 1) && isLeap === false) {
|
|
|
|
|
--i;
|
|
|
|
|
isLeap = true;
|
|
|
|
|
temp = this.leapDays(year); //计算农历闰月天数
|
|
|
|
|
} else {
|
|
|
|
|
temp = this.monthDays(year, i);//计算农历普通月天数
|
|
|
|
|
}
|
|
|
|
|
//解除闰月
|
|
|
|
|
if (isLeap === true && i === (leap + 1)) {
|
|
|
|
|
isLeap = false;
|
|
|
|
|
}
|
|
|
|
|
offset -= temp;
|
|
|
|
|
}
|
|
|
|
|
// 闰月导致数组下标重叠取反
|
|
|
|
|
if (offset === 0 && leap > 0 && i === leap + 1) {
|
|
|
|
|
if (isLeap) {
|
|
|
|
|
isLeap = false;
|
|
|
|
|
} else {
|
|
|
|
|
isLeap = true;
|
|
|
|
|
--i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (offset < 0) {
|
|
|
|
|
offset += temp;
|
|
|
|
|
--i;
|
|
|
|
|
}
|
|
|
|
|
//农历月
|
|
|
|
|
const month = i;
|
|
|
|
|
//农历日
|
|
|
|
|
const day = offset + 1;
|
|
|
|
|
//天干地支处理
|
|
|
|
|
const sm = m - 1;
|
|
|
|
|
|
|
|
|
|
//日柱 当月一日与 1900/1/1 相差天数
|
|
|
|
|
const dayCyclical = Date.UTC(y, sm, 1, 0, 0, 0, 0) / 86400000 + 25567 + 10;
|
|
|
|
|
|
|
|
|
|
const solarDate = y + '-' + m + '-' + d;
|
|
|
|
|
const lunarDate = year + '-' + month + '-' + day;
|
|
|
|
|
|
|
|
|
|
const lFestival = this.lFestival;
|
|
|
|
|
let lunarFestivalDate = month + '-' + day;
|
|
|
|
|
|
|
|
|
|
// 农历节日修正:农历12月小月则29号除夕,大月则30号除夕
|
|
|
|
|
// 此处取巧修正:当前为农历12月29号时增加一次判断并且把lunarFestivalDate设置为12-30以正确取得除夕
|
|
|
|
|
// 天朝农历节日遇闰月过前不过后的原则,此处取农历12月天数不考虑闰月
|
|
|
|
|
// 农历润12月在本工具支持的200年区间内仅1574年出现
|
|
|
|
|
if (month === 12 && day === 29 && this.monthDays(year, month) === 29) {
|
|
|
|
|
lunarFestivalDate = '12-30';
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
date: solarDate,
|
|
|
|
|
lunarDate: lunarDate,
|
|
|
|
|
lunarFestival: lFestival[lunarFestivalDate] ? lFestival[lunarFestivalDate].title : null,
|
|
|
|
|
'lYear': year,
|
|
|
|
|
'lMonth': month,
|
|
|
|
|
'lDay': day,
|
|
|
|
|
'Animal': this.getAnimal(year),
|
|
|
|
|
'Zodiac': this.getZodiac(year),
|
|
|
|
|
'IMonthCn': (isLeap ? "\u95f0" : '') + this.toChinaMonth(month),
|
|
|
|
|
'IDayCn': this.toChinaDay(day),
|
|
|
|
|
'cYear': y,
|
|
|
|
|
'cMonth': m,
|
|
|
|
|
'cDay': d,
|
|
|
|
|
'isLeap': isLeap,
|
|
|
|
|
'nWeek': nWeek,
|
|
|
|
|
'ncWeek': "\u661f\u671f" + cWeek
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|