fixLunarMonthIndex function
调整农历月份的索引
正月建寅(正月地支为寅),fixLeap为是否调整闰月情况 若调整闰月,则闰月的前15天按上月算,后面天数按下月算 比如 闰二月 时,fixLeap 为 true 时 闰二月十五(含)前 的月份按二月算,之后的按三月算
@param {string} solarDateStr 阳历日期 @param {number} timeIndex 时辰序号 @param {boolean} fixLeap 是否调整闰月 @returns {number} 月份索引
Implementation
int fixLunarMonthIndex(String solarDateStr, int timeIndex, bool? fixLeap) {
final lunar = solar2Lunar(solarDateStr);
final firstIndex = earthlyBranches.indexOf('yinEarthly');
if (fixLeap != null) {
final needToAdd =
lunar.isLeap && fixLeap! && lunar.lunarDay > 15 && timeIndex != 12;
return fixIndex(lunar.lunarMonth + 1 - firstIndex + (needToAdd ? 1 : 0));
}
return fixIndex(lunar.lunarMonth + 1 - firstIndex);
}