修复节气计算/佛历倒计时/顶部固定高度+老黄历方框
- 节气改用精确查表(2000-2060天文算法生成),修复立秋等大偏差 - 佛历倒计时/节日速查以当前选中日期为基准,切换日期实时更新 - 大日历顶部节日区/佛历区固定高度,空着也占位不再跳动 - 大日期加老黄历式方框(双线边框,节假日红/工作日绿)
This commit is contained in:
@@ -75,6 +75,71 @@ const SOLAR_TERM_DATES = [
|
||||
[7, 22] // 大雪, 冬至 (12月)
|
||||
];
|
||||
|
||||
/** 二十四节气精确日期表 2000-2060(天文算法生成,索引:小寒=0...冬至=23) */
|
||||
const SOLAR_TERM_TABLE = {
|
||||
2000: [6,21,4,19,5,20,4,20,5,21,5,21,7,22,7,23,7,23,8,23,7,22,7,21],
|
||||
2001: [5,20,4,18,5,20,5,20,5,21,5,21,7,23,7,23,7,23,8,23,7,22,7,22],
|
||||
2002: [5,20,4,19,6,21,5,20,6,21,6,21,7,23,8,23,8,23,8,23,7,22,7,22],
|
||||
2003: [6,20,4,19,6,21,5,20,6,21,6,22,7,23,8,23,8,23,9,24,8,23,7,22],
|
||||
2004: [6,21,4,19,5,20,4,20,5,21,5,21,7,22,7,23,7,23,8,23,7,22,7,21],
|
||||
2005: [5,20,4,18,5,20,5,20,5,21,5,21,7,23,7,23,7,23,8,23,7,22,7,22],
|
||||
2006: [5,20,4,19,6,21,5,20,5,21,6,21,7,23,7,23,8,23,8,23,7,22,7,22],
|
||||
2007: [6,20,4,19,6,21,5,20,6,21,6,22,7,23,8,23,8,23,9,24,8,23,7,22],
|
||||
2008: [6,21,4,19,5,20,4,20,5,21,5,21,7,22,7,23,7,22,8,23,7,22,7,21],
|
||||
2009: [5,20,4,18,5,20,4,20,5,21,5,21,7,23,7,23,7,23,8,23,7,22,7,22],
|
||||
2010: [5,20,4,19,6,21,5,20,5,21,6,21,7,23,7,23,8,23,8,23,7,22,7,22],
|
||||
2011: [6,20,4,19,6,21,5,20,6,21,6,22,7,23,8,23,8,23,8,24,8,23,7,22],
|
||||
2012: [6,21,4,19,5,20,4,20,5,20,5,21,7,22,7,23,7,22,8,23,7,22,7,21],
|
||||
2013: [5,20,4,18,5,20,4,20,5,21,5,21,7,22,7,23,7,23,8,23,7,22,7,22],
|
||||
2014: [5,20,4,19,6,21,5,20,5,21,6,21,7,23,7,23,8,23,8,23,7,22,7,22],
|
||||
2015: [6,20,4,19,6,21,5,20,6,21,6,22,7,23,8,23,8,23,8,24,8,22,7,22],
|
||||
2016: [6,20,4,19,5,20,4,19,5,20,5,21,7,22,7,23,7,22,8,23,7,22,7,21],
|
||||
2017: [5,20,3,18,5,20,4,20,5,21,5,21,7,22,7,23,7,23,8,23,7,22,7,22],
|
||||
2018: [5,20,4,19,5,21,5,20,5,21,6,21,7,23,7,23,8,23,8,23,7,22,7,22],
|
||||
2019: [5,20,4,19,6,21,5,20,6,21,6,21,7,23,8,23,8,23,8,24,8,22,7,22],
|
||||
2020: [6,20,4,19,5,20,4,19,5,20,5,21,6,22,7,22,7,22,8,23,7,22,7,21],
|
||||
2021: [5,20,3,18,5,20,4,20,5,21,5,21,7,22,7,23,7,23,8,23,7,22,7,21],
|
||||
2022: [5,20,4,19,5,20,5,20,5,21,6,21,7,23,7,23,7,23,8,23,7,22,7,22],
|
||||
2023: [5,20,4,19,6,21,5,20,6,21,6,21,7,23,8,23,8,23,8,24,8,22,7,22],
|
||||
2024: [6,20,4,19,5,20,4,19,5,20,5,21,6,22,7,22,7,22,8,23,7,22,6,21],
|
||||
2025: [5,20,3,18,5,20,4,20,5,21,5,21,7,22,7,23,7,23,8,23,7,22,7,21],
|
||||
2026: [5,20,4,18,5,20,5,20,5,21,5,21,7,23,7,23,7,23,8,23,7,22,7,22],
|
||||
2027: [5,20,4,19,6,21,5,20,6,21,6,21,7,23,8,23,8,23,8,23,7,22,7,22],
|
||||
2028: [6,20,4,19,5,20,4,19,5,20,5,21,6,22,7,22,7,22,8,23,7,22,6,21],
|
||||
2029: [5,20,3,18,5,20,4,20,5,21,5,21,7,22,7,23,7,23,8,23,7,22,7,21],
|
||||
2030: [5,20,4,18,5,20,5,20,5,21,5,21,7,23,7,23,7,23,8,23,7,22,7,22],
|
||||
2031: [5,20,4,19,6,21,5,20,6,21,6,21,7,23,8,23,8,23,8,23,7,22,7,22],
|
||||
2032: [6,20,4,19,5,20,4,19,5,20,5,21,6,22,7,22,7,22,8,23,7,22,6,21],
|
||||
2033: [5,20,3,18,5,20,4,20,5,21,5,21,7,22,7,23,7,23,8,23,7,22,7,21],
|
||||
2034: [5,20,4,18,5,20,5,20,5,21,5,21,7,23,7,23,7,23,8,23,7,22,7,22],
|
||||
2035: [5,20,4,19,6,21,5,20,5,21,6,21,7,23,7,23,8,23,8,23,7,22,7,22],
|
||||
2036: [6,20,4,19,5,20,4,19,5,20,5,21,6,22,7,22,7,22,8,23,7,22,6,21],
|
||||
2037: [5,20,3,18,5,20,4,20,5,21,5,21,7,22,7,23,7,23,8,23,7,22,7,21],
|
||||
2038: [5,20,4,18,5,20,5,20,5,21,5,21,7,23,7,23,7,23,8,23,7,22,7,22],
|
||||
2039: [5,20,4,19,6,21,5,20,5,21,6,21,7,23,7,23,8,23,8,23,7,22,7,22],
|
||||
2040: [6,20,4,19,5,20,4,19,5,20,5,21,6,22,7,22,7,22,8,23,7,22,6,21],
|
||||
2041: [5,20,3,18,5,20,4,20,5,20,5,21,7,22,7,23,7,22,8,23,7,22,7,21],
|
||||
2042: [5,20,4,18,5,20,4,20,5,21,5,21,7,23,7,23,7,23,8,23,7,22,7,22],
|
||||
2043: [5,20,4,19,6,21,5,20,5,21,6,21,7,23,7,23,8,23,8,23,7,22,7,22],
|
||||
2044: [6,20,4,19,5,20,4,19,5,20,5,21,6,22,7,22,7,22,7,23,7,22,6,21],
|
||||
2045: [5,20,3,18,5,20,4,19,5,20,5,21,7,22,7,23,7,22,8,23,7,22,7,21],
|
||||
2046: [5,20,4,18,5,20,4,20,5,21,5,21,7,22,7,23,7,23,8,23,7,22,7,22],
|
||||
2047: [5,20,4,19,6,21,5,20,5,21,6,21,7,23,7,23,8,23,8,23,7,22,7,22],
|
||||
2048: [6,20,4,19,5,20,4,19,5,20,5,20,6,22,7,22,7,22,7,23,7,21,6,21],
|
||||
2049: [5,19,3,18,5,20,4,19,5,20,5,21,6,22,7,22,7,22,8,23,7,22,7,21],
|
||||
2050: [5,20,3,18,5,20,4,20,5,21,5,21,7,22,7,23,7,23,8,23,7,22,7,22],
|
||||
2051: [5,20,4,19,5,20,5,20,5,21,6,21,7,23,7,23,7,23,8,23,7,22,7,22],
|
||||
2052: [5,20,4,19,5,20,4,19,5,20,5,20,6,22,7,22,7,22,7,23,7,21,6,21],
|
||||
2053: [5,19,3,18,5,20,4,19,5,20,5,21,6,22,7,22,7,22,8,23,7,22,7,21],
|
||||
2054: [5,20,3,18,5,20,4,20,5,21,5,21,7,22,7,23,7,23,8,23,7,22,7,22],
|
||||
2055: [5,20,4,19,5,20,5,20,5,21,5,21,7,23,7,23,7,23,8,23,7,22,7,22],
|
||||
2056: [5,20,4,19,5,20,4,19,5,20,5,20,6,22,7,22,7,22,7,23,7,21,6,21],
|
||||
2057: [5,19,3,18,5,20,4,19,5,20,5,21,6,22,7,22,7,22,8,23,7,22,6,21],
|
||||
2058: [5,20,3,18,5,20,4,20,5,21,5,21,7,22,7,23,7,23,8,23,7,22,7,21],
|
||||
2059: [5,20,4,19,5,20,5,20,5,21,5,21,7,23,7,23,7,23,8,23,7,22,7,22],
|
||||
2060: [5,20,4,19,5,20,4,19,5,20,5,20,6,22,7,22,7,22,7,22,6,21,6,21],
|
||||
};
|
||||
|
||||
/** 公历节日 */
|
||||
const SOLAR_FESTIVALS = {
|
||||
'1-1': '元旦', '2-14': '情人节', '3-8': '妇女节', '3-12': '植树节',
|
||||
@@ -415,6 +480,7 @@ module.exports = {
|
||||
CONSTELLATION_DATES,
|
||||
SOLAR_TERMS,
|
||||
SOLAR_TERM_DATES,
|
||||
SOLAR_TERM_TABLE,
|
||||
SOLAR_FESTIVALS,
|
||||
LUNAR_FESTIVALS,
|
||||
BUDDHIST_FESTIVALS,
|
||||
|
||||
+24
-11
@@ -10,6 +10,7 @@ const {
|
||||
CONSTELLATION_DATES,
|
||||
SOLAR_TERMS,
|
||||
SOLAR_TERM_DATES,
|
||||
SOLAR_TERM_TABLE,
|
||||
SOLAR_FESTIVALS,
|
||||
LUNAR_FESTIVALS,
|
||||
BUDDHIST_FESTIVALS,
|
||||
@@ -316,7 +317,7 @@ function getSolarTermDate(year, termIndex) {
|
||||
return Math.floor(Y * 0.2422 + C) - Math.floor(Y / 4) + leapAdjust;
|
||||
}
|
||||
|
||||
/** 获取节气(准确算法)
|
||||
/** 获取节气(优先精确查表 2000-2060,范围外用 C 值法兜底)
|
||||
* SOLAR_TERMS 数组从冬至开始:冬至=0, 小寒=1, 大寒=2, 立春=3, ..., 大雪=23
|
||||
*/
|
||||
function getSolarTerm(year, month, day) {
|
||||
@@ -327,6 +328,16 @@ function getSolarTerm(year, month, day) {
|
||||
// 转为天文顺序(小寒=0):SOLAR_TERMS 索引 - 1(冬至特殊为23)
|
||||
const astroIdx1 = idx1 === 0 ? 23 : idx1 - 1;
|
||||
const astroIdx2 = idx2 === 0 ? 23 : idx2 - 1;
|
||||
|
||||
// 优先用精确表
|
||||
const table = SOLAR_TERM_TABLE[year];
|
||||
if (table) {
|
||||
if (day === table[astroIdx1]) return SOLAR_TERMS[idx1];
|
||||
if (day === table[astroIdx2]) return SOLAR_TERMS[idx2];
|
||||
return null;
|
||||
}
|
||||
|
||||
// 兜底:C 值法
|
||||
const d1 = getSolarTermDate(year, astroIdx1);
|
||||
const d2 = getSolarTermDate(year, astroIdx2);
|
||||
if (day === d1) return SOLAR_TERMS[idx1];
|
||||
@@ -1209,12 +1220,14 @@ function daysBetween(fromY, fromM, fromD, toY, toM, toD) {
|
||||
return Math.round((b - a) / (24 * 60 * 60 * 1000));
|
||||
}
|
||||
|
||||
/** 获取即将到来的 N 个节日(含今天之后的) */
|
||||
function getUpcomingFestivals(count = 6) {
|
||||
/** 获取即将到来的 N 个节日(含基准日之后的)
|
||||
* baseYear/baseMonth/baseDay 可选,默认今天
|
||||
*/
|
||||
function getUpcomingFestivals(count = 6, baseYear, baseMonth, baseDay) {
|
||||
const now = new Date();
|
||||
const y = now.getFullYear();
|
||||
const m = now.getMonth() + 1;
|
||||
const d = now.getDate();
|
||||
const y = baseYear || now.getFullYear();
|
||||
const m = baseMonth || (now.getMonth() + 1);
|
||||
const d = baseDay || now.getDate();
|
||||
const list = [];
|
||||
|
||||
for (const fest of FESTIVAL_QUICK_SEARCH) {
|
||||
@@ -1241,12 +1254,12 @@ function getUpcomingFestivals(count = 6) {
|
||||
return list.slice(0, count);
|
||||
}
|
||||
|
||||
/** 获取下一个佛教节日及倒计时 */
|
||||
function getNextBuddhistFestival() {
|
||||
/** 获取下一个佛教节日及倒计时(基准日可选,默认今天) */
|
||||
function getNextBuddhistFestival(baseYear, baseMonth, baseDay) {
|
||||
const now = new Date();
|
||||
const y = now.getFullYear();
|
||||
const m = now.getMonth() + 1;
|
||||
const d = now.getDate();
|
||||
const y = baseYear || now.getFullYear();
|
||||
const m = baseMonth || (now.getMonth() + 1);
|
||||
const d = baseDay || now.getDate();
|
||||
|
||||
const entries = Object.entries(BUDDHIST_FESTIVALS);
|
||||
const list = [];
|
||||
|
||||
Reference in New Issue
Block a user