修复节气计算/佛历倒计时/顶部固定高度+老黄历方框

- 节气改用精确查表(2000-2060天文算法生成),修复立秋等大偏差
- 佛历倒计时/节日速查以当前选中日期为基准,切换日期实时更新
- 大日历顶部节日区/佛历区固定高度,空着也占位不再跳动
- 大日期加老黄历式方框(双线边框,节假日红/工作日绿)
This commit is contained in:
gouki
2026-08-07 22:57:26 +00:00
parent bb9c19c99f
commit 2bd84eea88
5 changed files with 130 additions and 24 deletions
+24 -11
View File
@@ -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 = [];