lunar-solar-converter
Version:
一个用于公历(阳历)和农历(阴历)转换的 TypeScript 工具库。基于 tyme4ts 实现,支持节假日、节气等信息的查询。
96 lines (95 loc) • 2.46 kB
TypeScript
import { SixtyCycle } from 'tyme4ts';
/**
* 日历日期类型
* @interface CalendarDate
* @property {number} year 公历年
* @property {number} month 公历月
* @property {number} day 公历日
* @property {string} yearName 农历年
* @property {string} monthName 农历月
* @property {string} dayName 农历日
* @property {string} zodiac 生肖
* @property {string} festival 农历节日
* @property {string} term 节气
* @property {boolean} work 是否为工作日
* @example
* {
* year: 2023,
* month: 1,
* day: 1,
}
*/
export interface CalendarDate {
year: number;
month: number;
day: number;
yearName?: string;
monthName?: string;
dayName?: string;
zodiac?: string;
festival?: string;
term?: string;
work?: boolean | null;
}
export declare class Calendar {
/**
* 公历转农历
* @param year 公历年
* @param month 公历月
* @param day 公历日
*/
static solarToLunar(year: number, month: number, day: number): CalendarDate;
/**
* 农历转公历
* @param year 农历年
* @param month 农历月
* @param day 农历日
* @param isLeapMonth 是否闰月
*/
static lunarToSolar(year: number, month: number, day: number, isLeapMonth?: boolean): CalendarDate;
/**
* 获取某月的农历日期数组
* @param year 公历年
* @param month 公历月
*/
static getLunarMonthDays(year: number, month: number): CalendarDate[];
/**
* 获取农历年份信息
* @param year 公历年份
*/
static getLunarYearInfo(year: number): {
year: number;
yearName: string;
};
/**
* 判断是否为闰月
* @param year 农历年
* @param month 农历月
*/
static isLeapMonth(year: number, month: number): boolean;
/**
* 获取某天的宜忌
*/
static getTaboos(year: number, month: number, day: number): {
recommend: string[];
avoid: string[];
};
/**
* 获取当天的彭祖百忌
*/
static getPenZu(year: number, month: number, day: number): PengZuAvoid;
}
interface PengZuAvoid {
heavenStem: string;
earthBranch: string;
}
/**
*
* @param sixtyCycle 六十甲子
* @returns {
* heavenStem: string; // 天干彭祖百忌
* earthBranch: string; // 地支彭祖百忌
* }
*/
export declare function getPengZu(sixtyCycle: SixtyCycle): PengZuAvoid;
export {};