0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45,
0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0
}
-- 更新节气数据(每个节气的日期偏移量)
local SOLAR_TERMS_OFFSET = {
5, 20, 3, 18, 5, 20, 4, 19, 5, 20, 5, 21,
6, 22, 7, 22, 7, 22, 7, 23, 7, 22, 6, 21
}
-- 节气名称
local SOLAR_TERMS = {
'小寒', '大寒', '立春', '雨水', '惊蛰', '春分',
'清明', '谷雨', '立夏', '小满', '芒种', '夏至',
'小暑', '大暑', '立秋', '处暑', '白露', '秋分',
'寒露', '霜降', '立冬', '小雪', '大雪', '冬至'
}
local day = extract(lunarCode, 18, 5)
return month, day
end
-- 计算节气的修正值
local function getTermOffset(year, termIndex)
local y = year - 1900
local d = 0
-- 针对不同节气使用不同的系数
local coefficient = 0.2422
if termIndex <= 2 then -- 小寒、大寒
d = math.floor(y * coefficient + 4.81) - math.floor(y/4)
elseif termIndex <= 6 then -- 立春到春分
d = math.floor(y * coefficient + 4.6) - math.floor(y/4)
elseif termIndex <= 12 then -- 清明到夏至
d = math.floor(y * coefficient + 4.8) - math.floor(y/4)
elseif termIndex <= 18 then -- 小暑到秋分
d = math.floor(y * coefficient + 4.87) - math.floor(y/4)
else -- 寒露到冬至
d = math.floor(y * coefficient + 4.83) - math.floor(y/4)
end
return d
end
-- 计算节气
local function getSolarTerm(year, month, day)
local termIndex = (month - 1) * 2 + 1
for i = 0, 1 do
local idx = termIndex + i
local baseDay = SOLAR_TERMS_OFFSET[idx]
local offset = getTermOffset(year, idx)
local termDay = (baseDay + offset) % 31
if termDay == 0 then termDay = 31 end
if day == termDay then
return SOLAR_TERMS[idx]
end
end
return nil
end
end
result = result .. LUNAR_MONTHS[lunarMonth] .. '月' .. LUNAR_DAYS[lunarDay]
-- 输出节气
if showSolarTerm then
local solarTerm = getSolarTerm(year, month, day)
if solarTerm then
result = result .. '(' .. solarTerm .. ')'
end
end
return result
|