This commit is contained in:
2025-06-10 22:04:23 +08:00
parent c0b62dfa0f
commit df13a5b6c3
11 changed files with 652 additions and 516 deletions

View File

@@ -1,5 +1,18 @@
import dayjs from 'dayjs';
import * as chineseLunar from 'chinese-lunar';
import { getLunar } from 'chinese-lunar-calendar'
const lunarMonthArray = [
'正', '二', '三', '四', '五', '六', '七', '八', '九', '十',
'十一', '十二'
];
const lunarArray = [
'初一', '初二', '初三', '初四', '初五', '初六', '初七', '初八', '初九', '初十',
'十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十',
'廿一', '廿二', '廿三', '廿四', '廿五', '廿六', '廿七', '廿八', '廿九', '三十'
];
/**
* 获取农历日期
@@ -8,19 +21,16 @@ import * as chineseLunar from 'chinese-lunar';
*/
export function getLunarDate(date) {
try {
// 使用chinese-lunar库获取农历信息
const lunar = chineseLunar.solarToLunar(new Date(date));
const month = chineseLunar.format(lunar, 'M');
const day = chineseLunar.format(lunar, 'D');
const d = dayjs(date);
console.log(date, chineseLunar.dayName(lunar))
// console.log(date, lunar, month + day)
if (day === '初一') {
return month;
} else {
return day;
}
const year = d.year();
const month = d.month() + 1;
const day = d.date();
const result = getLunar(year, month, day);
console.log(getLunar(year, month, day));
return result.dateStr;
} catch (error) {
console.error('获取农历日期错误:', error);
return '';
@@ -116,4 +126,4 @@ export function isHoliday(date) {
console.error('判断假日错误:', error);
return false;
}
}
}