@sanguo-dev/calendar 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +229 -3
- package/dist/index.cjs +1766 -0
- package/dist/index.d.cts +269 -0
- package/dist/index.d.mts +269 -0
- package/dist/index.iife.js +1769 -0
- package/dist/index.mjs +1760 -0
- package/dist/index.umd.js +1770 -0
- package/package.json +68 -6
- package/src/config.ts +198 -0
- package/src/data/Calendar.ts +599 -0
- package/src/data/festival.json +195 -0
- package/src/data/rest.json +74 -0
- package/src/index.ts +317 -0
- package/src/types.ts +146 -0
- package/src/utils/Assert.ts +230 -0
- package/src/utils/LunarFunction.ts +215 -0
- package/src/utils/SetFestival.ts +40 -0
- package/src/utils/SetRest.ts +84 -0
- package/src/utils/SolarFunction.ts +162 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 返回农历 y 年一整年的总天数
|
|
3
|
+
* @param y 农历年(1900-2100)
|
|
4
|
+
* @return 348-385
|
|
5
|
+
*/
|
|
6
|
+
declare const lYearDays: (y: number) => number;
|
|
7
|
+
/**
|
|
8
|
+
* 返回农历 y 年闰月是哪个月;没有闰月返回 0
|
|
9
|
+
* @param y 农历年(1900-2100)
|
|
10
|
+
*/
|
|
11
|
+
declare const leapMonth: (y: number) => number;
|
|
12
|
+
/**
|
|
13
|
+
* 返回农历 y 年闰月的天数;没有闰月返回 0
|
|
14
|
+
* @param y 农历年(1900-2100)
|
|
15
|
+
*/
|
|
16
|
+
declare const leapDays: (y: number) => number;
|
|
17
|
+
/**
|
|
18
|
+
* 返回农历 y 年 m 月(非闰月)的天数,闰月天数请用 leapDays
|
|
19
|
+
* @param y 农历年(1900-2100)
|
|
20
|
+
* @param m 农历月(1-12)
|
|
21
|
+
*/
|
|
22
|
+
declare const lMonthDays: (y: number, m: number) => number;
|
|
23
|
+
/**
|
|
24
|
+
* 农历年转换为干支纪年
|
|
25
|
+
* @param lYear 农历年,允许 1899 这类边界年(只做算术,不查表)
|
|
26
|
+
*/
|
|
27
|
+
declare const toGanZhiYear: (lYear: number) => string;
|
|
28
|
+
/**
|
|
29
|
+
* 传入相对甲子的偏移量返回干支
|
|
30
|
+
* @param offset 可以为负数
|
|
31
|
+
*/
|
|
32
|
+
declare const toGanZhi: (offset: number) => string;
|
|
33
|
+
/**
|
|
34
|
+
* 传入当天的干支偏移量,返回当天十二个时辰的干支
|
|
35
|
+
* @param offset 相对甲子的偏移量(与 gzDay 用同一个偏移量)
|
|
36
|
+
*/
|
|
37
|
+
declare const toHourGanZhi: (offset: number) => string[];
|
|
38
|
+
/**
|
|
39
|
+
* 农历数字月份转中文,例如 1 -> "正月"、12 -> "腊月"
|
|
40
|
+
* @param m 农历月(1-12)
|
|
41
|
+
*/
|
|
42
|
+
declare const toChinaMonth: (m: number) => string;
|
|
43
|
+
/**
|
|
44
|
+
* 农历日期数字转中文,例如 1 -> "初一"、21 -> "廿一"
|
|
45
|
+
* @param d 农历日(1-30)
|
|
46
|
+
*/
|
|
47
|
+
declare const toChinaDay: (d: number) => string;
|
|
48
|
+
/**
|
|
49
|
+
* 取第 n 个节气名(n 从 0 开始,0 为小寒)
|
|
50
|
+
* @param n 0-23
|
|
51
|
+
*/
|
|
52
|
+
declare const getSolarTerm: (n: number) => string;
|
|
53
|
+
/**
|
|
54
|
+
* 返回公历 y 年 m 月的天数(会自动处理闰年)
|
|
55
|
+
* @param y 公历年
|
|
56
|
+
* @param m 公历月(1-12)
|
|
57
|
+
* @return 28-31
|
|
58
|
+
*/
|
|
59
|
+
declare const solarDays: (y: number, m: number) => number;
|
|
60
|
+
/**
|
|
61
|
+
* 返回公历 y 年 m 月 1 日是星期几
|
|
62
|
+
* @param y 公历年
|
|
63
|
+
* @param m 公历月(1-12)
|
|
64
|
+
* @return 0-6,0 为周日
|
|
65
|
+
*/
|
|
66
|
+
declare const solarFirstWeek: (y: number, m: number) => number;
|
|
67
|
+
/**
|
|
68
|
+
* 返回公历 y 年 m 月第 nth 个星期 weekday 是几号
|
|
69
|
+
* @param y 公历年
|
|
70
|
+
* @param m 公历月(1-12)
|
|
71
|
+
* @param weekday 0-6,0 为周日
|
|
72
|
+
* @param nth 第几个,从 1 开始
|
|
73
|
+
* @example nthWeekdayOfMonth(2026, 5, 0, 2) // 10,2026 年母亲节是 5 月 10 日
|
|
74
|
+
*/
|
|
75
|
+
declare const nthWeekdayOfMonth: (y: number, m: number, weekday: number, nth: number) => number;
|
|
76
|
+
/**
|
|
77
|
+
* 公历月、日判断所属星座
|
|
78
|
+
* @param m 公历月(1-12)
|
|
79
|
+
* @param d 公历日
|
|
80
|
+
* @example toAstro(4, 19) // "白羊座"
|
|
81
|
+
*/
|
|
82
|
+
declare const toAstro: (m: number, d: number) => string;
|
|
83
|
+
/**
|
|
84
|
+
* 传入公历年获得该年第 n 个节气所在公历月的日期
|
|
85
|
+
* @param y 公历年(1900-2100)
|
|
86
|
+
* @param n 第几个节气(1-24),1 为小寒
|
|
87
|
+
* @return 日期数字
|
|
88
|
+
* @example getTerm(1987, 3) // 4,1987 年 2 月 4 日立春
|
|
89
|
+
*/
|
|
90
|
+
declare const getTerm: (y: number, n: number) => number;
|
|
91
|
+
/**
|
|
92
|
+
* 年份转生肖,以农历年为准
|
|
93
|
+
* @param y 年份
|
|
94
|
+
* @example getAnimal(1987) // "兔"
|
|
95
|
+
*/
|
|
96
|
+
declare const getAnimal: (y: number) => string;
|
|
97
|
+
/**
|
|
98
|
+
* 数字转中文,0-10
|
|
99
|
+
* @param num 0-10
|
|
100
|
+
* @example toChinaNum(3) // "三"
|
|
101
|
+
*/
|
|
102
|
+
declare const toChinaNum: (num: number) => string;
|
|
103
|
+
/**
|
|
104
|
+
* 公历节日 / 农历节日的映射表
|
|
105
|
+
* key 为四位 "MMDD",value 为节日名称数组
|
|
106
|
+
*/
|
|
107
|
+
type FestivalMap = Record<string, string[]>;
|
|
108
|
+
/**
|
|
109
|
+
* 节日配置,sFtv 为公历节日,lFtv 为农历节日
|
|
110
|
+
*/
|
|
111
|
+
interface FestivalConfig {
|
|
112
|
+
/** 公历节日,key 为 MMDD,例如 { "0101": ["元旦"] } */
|
|
113
|
+
sFtv?: FestivalMap;
|
|
114
|
+
/** 农历节日,key 为 MMDD,例如 { "0101": ["春节"] } */
|
|
115
|
+
lFtv?: FestivalMap;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 单年的放假与调休配置(用户注入时的形态,两个数组都可省略)
|
|
119
|
+
*/
|
|
120
|
+
interface RestEntry {
|
|
121
|
+
/** 该年放假日(MMDD),不含普通周末 */
|
|
122
|
+
xiu?: string[];
|
|
123
|
+
/** 该年调休补班日(MMDD),一般是周末上班 */
|
|
124
|
+
ban?: string[];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 归一化之后的单年配置:两个数组一定存在,内部查询用
|
|
128
|
+
*/
|
|
129
|
+
interface NormalizedRestEntry {
|
|
130
|
+
xiu: string[];
|
|
131
|
+
ban: string[];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 调休配置,key 为年份,value 为该年的放假/补班日
|
|
135
|
+
*/
|
|
136
|
+
type RestConfig = Record<string | number, RestEntry>;
|
|
137
|
+
/**
|
|
138
|
+
* getHolidays() 的返回值:结构完整,可直接再传给 createCalendar()
|
|
139
|
+
*/
|
|
140
|
+
interface HolidaySnapshot {
|
|
141
|
+
setFestival: {
|
|
142
|
+
sFtv: FestivalMap;
|
|
143
|
+
lFtv: FestivalMap;
|
|
144
|
+
};
|
|
145
|
+
setRest: Record<string, NormalizedRestEntry>;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* createCalendar 的入参
|
|
149
|
+
*/
|
|
150
|
+
interface HolidayConfig {
|
|
151
|
+
setFestival?: FestivalConfig;
|
|
152
|
+
setRest?: RestConfig;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* createCalendar 的选项
|
|
156
|
+
*/
|
|
157
|
+
interface SetHolidayOptions {
|
|
158
|
+
/** 为 true 时丢弃内置节日/调休数据,只使用传入的数据 */
|
|
159
|
+
replace?: boolean;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 公历转农历 / 农历转公历的完整结果
|
|
163
|
+
*/
|
|
164
|
+
interface LunarResult {
|
|
165
|
+
/** 是否在 rest.json 的放假日列表(xiu)中;与周末无关 */
|
|
166
|
+
xiu: boolean;
|
|
167
|
+
/** 是否在 rest.json 的调休补班日列表(ban)中 */
|
|
168
|
+
ban: boolean;
|
|
169
|
+
/** 公历节日,例如 ["元旦"];没有节日时是共享的只读空数组 */
|
|
170
|
+
gljr: readonly string[];
|
|
171
|
+
/** 农历节日,例如 ["春节"];没有节日时是共享的只读空数组 */
|
|
172
|
+
nljr: readonly string[];
|
|
173
|
+
/** 农历年 */
|
|
174
|
+
lYear: number;
|
|
175
|
+
/** 农历月,1-12 */
|
|
176
|
+
lMonth: number;
|
|
177
|
+
/** 农历日,1-30 */
|
|
178
|
+
lDay: number;
|
|
179
|
+
/** 生肖,以农历年为准 */
|
|
180
|
+
animal: string;
|
|
181
|
+
/** 农历月中文名,例如 "正月"、"闰四月" */
|
|
182
|
+
lMonthCn: string;
|
|
183
|
+
/** 农历日中文名,例如 "初一" */
|
|
184
|
+
lDayCn: string;
|
|
185
|
+
/** 公历年 */
|
|
186
|
+
cYear: number;
|
|
187
|
+
/** 公历月,1-12 */
|
|
188
|
+
cMonth: number;
|
|
189
|
+
/** 公历日 */
|
|
190
|
+
cDay: number;
|
|
191
|
+
/** 干支年,以立春为界,与 gzMonth 口径一致 */
|
|
192
|
+
gzYear: string;
|
|
193
|
+
/** 干支年,以正月初一为界,与 animal 口径一致 */
|
|
194
|
+
gzYearLunar: string;
|
|
195
|
+
/** 干支月,以节气为界 */
|
|
196
|
+
gzMonth: string;
|
|
197
|
+
/** 干支日 */
|
|
198
|
+
gzDay: string;
|
|
199
|
+
/** 当天十二个时辰的干支 */
|
|
200
|
+
gzHour: string[];
|
|
201
|
+
/** 是否今天(按本地时区) */
|
|
202
|
+
isToday: boolean;
|
|
203
|
+
/** 是否闰月 */
|
|
204
|
+
isLeap: boolean;
|
|
205
|
+
/** 星期数字,1-7,周一为 1、周日为 7 */
|
|
206
|
+
nWeek: number;
|
|
207
|
+
/** 星期数字,0-6,周日为 0,与 solarFirstWeek 口径一致 */
|
|
208
|
+
dayOfWeek: number;
|
|
209
|
+
/** 星期中文,例如 "星期日" */
|
|
210
|
+
ncWeek: string;
|
|
211
|
+
/** 节气名,当天不是节气时为 null */
|
|
212
|
+
term: string | null;
|
|
213
|
+
/** 星座,例如 "摩羯座" */
|
|
214
|
+
astro: string;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* getHolidays 的选项
|
|
218
|
+
*/
|
|
219
|
+
interface GetHolidaysOptions {
|
|
220
|
+
/** 默认 true:返回合并内置数据后的完整配置;false:只返回创建实例时传入的那部分 */
|
|
221
|
+
merged?: boolean;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* 固定了一份节假日配置的日历实例
|
|
225
|
+
*
|
|
226
|
+
* 由 createCalendar() 创建,配置在创建时固定,实例之间互不影响。
|
|
227
|
+
*/
|
|
228
|
+
interface Calendar {
|
|
229
|
+
/** 公历转农历,不传参返回今天 */
|
|
230
|
+
solarToLunar(this: void, y?: number, m?: number, d?: number): LunarResult;
|
|
231
|
+
/** 农历转公历 */
|
|
232
|
+
lunarToSolar(this: void, y: number, m: number, d: number, isLeapMonth?: boolean): LunarResult;
|
|
233
|
+
/** 该实例当前配置的深拷贝,可再次用于 createCalendar() */
|
|
234
|
+
getHolidays(this: void, options?: GetHolidaysOptions): HolidaySnapshot;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* 创建固定节假日配置的日历实例
|
|
238
|
+
*
|
|
239
|
+
* 不读取也不修改任何全局状态;配置在创建时校验并冻结,
|
|
240
|
+
* 多个实例之间互不影响。不传配置时使用内置数据。
|
|
241
|
+
*
|
|
242
|
+
* @param config 节假日 / 调休配置
|
|
243
|
+
* @param options replace 为 true 时忽略内置数据
|
|
244
|
+
* @throws TypeError 配置格式不合法(含具体字段路径)
|
|
245
|
+
* @example
|
|
246
|
+
* const cc = createCalendar({ setRest: { 2027: { xiu: ["0101"] } } });
|
|
247
|
+
* cc.solarToLunar(2027, 1, 1).xiu; // true
|
|
248
|
+
*/
|
|
249
|
+
declare const createCalendar: (config?: HolidayConfig, options?: SetHolidayOptions) => Calendar;
|
|
250
|
+
declare const utils: {
|
|
251
|
+
lYearDays: typeof lYearDays;
|
|
252
|
+
leapMonth: typeof leapMonth;
|
|
253
|
+
leapDays: typeof leapDays;
|
|
254
|
+
lMonthDays: typeof lMonthDays;
|
|
255
|
+
toChinaMonth: typeof toChinaMonth;
|
|
256
|
+
toChinaDay: typeof toChinaDay;
|
|
257
|
+
toChinaNum: typeof toChinaNum;
|
|
258
|
+
solarDays: typeof solarDays;
|
|
259
|
+
solarFirstWeek: typeof solarFirstWeek;
|
|
260
|
+
nthWeekdayOfMonth: typeof nthWeekdayOfMonth;
|
|
261
|
+
toAstro: typeof toAstro;
|
|
262
|
+
getAnimal: typeof getAnimal;
|
|
263
|
+
getTerm: typeof getTerm;
|
|
264
|
+
getSolarTerm: typeof getSolarTerm;
|
|
265
|
+
toGanZhi: typeof toGanZhi;
|
|
266
|
+
toGanZhiYear: typeof toGanZhiYear;
|
|
267
|
+
toHourGanZhi: typeof toHourGanZhi;
|
|
268
|
+
};
|
|
269
|
+
export { type Calendar, type FestivalConfig, type FestivalMap, type GetHolidaysOptions, type HolidayConfig, type HolidaySnapshot, type LunarResult, type RestConfig, type RestEntry, type SetHolidayOptions, createCalendar, createCalendar as default, utils };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 返回农历 y 年一整年的总天数
|
|
3
|
+
* @param y 农历年(1900-2100)
|
|
4
|
+
* @return 348-385
|
|
5
|
+
*/
|
|
6
|
+
declare const lYearDays: (y: number) => number;
|
|
7
|
+
/**
|
|
8
|
+
* 返回农历 y 年闰月是哪个月;没有闰月返回 0
|
|
9
|
+
* @param y 农历年(1900-2100)
|
|
10
|
+
*/
|
|
11
|
+
declare const leapMonth: (y: number) => number;
|
|
12
|
+
/**
|
|
13
|
+
* 返回农历 y 年闰月的天数;没有闰月返回 0
|
|
14
|
+
* @param y 农历年(1900-2100)
|
|
15
|
+
*/
|
|
16
|
+
declare const leapDays: (y: number) => number;
|
|
17
|
+
/**
|
|
18
|
+
* 返回农历 y 年 m 月(非闰月)的天数,闰月天数请用 leapDays
|
|
19
|
+
* @param y 农历年(1900-2100)
|
|
20
|
+
* @param m 农历月(1-12)
|
|
21
|
+
*/
|
|
22
|
+
declare const lMonthDays: (y: number, m: number) => number;
|
|
23
|
+
/**
|
|
24
|
+
* 农历年转换为干支纪年
|
|
25
|
+
* @param lYear 农历年,允许 1899 这类边界年(只做算术,不查表)
|
|
26
|
+
*/
|
|
27
|
+
declare const toGanZhiYear: (lYear: number) => string;
|
|
28
|
+
/**
|
|
29
|
+
* 传入相对甲子的偏移量返回干支
|
|
30
|
+
* @param offset 可以为负数
|
|
31
|
+
*/
|
|
32
|
+
declare const toGanZhi: (offset: number) => string;
|
|
33
|
+
/**
|
|
34
|
+
* 传入当天的干支偏移量,返回当天十二个时辰的干支
|
|
35
|
+
* @param offset 相对甲子的偏移量(与 gzDay 用同一个偏移量)
|
|
36
|
+
*/
|
|
37
|
+
declare const toHourGanZhi: (offset: number) => string[];
|
|
38
|
+
/**
|
|
39
|
+
* 农历数字月份转中文,例如 1 -> "正月"、12 -> "腊月"
|
|
40
|
+
* @param m 农历月(1-12)
|
|
41
|
+
*/
|
|
42
|
+
declare const toChinaMonth: (m: number) => string;
|
|
43
|
+
/**
|
|
44
|
+
* 农历日期数字转中文,例如 1 -> "初一"、21 -> "廿一"
|
|
45
|
+
* @param d 农历日(1-30)
|
|
46
|
+
*/
|
|
47
|
+
declare const toChinaDay: (d: number) => string;
|
|
48
|
+
/**
|
|
49
|
+
* 取第 n 个节气名(n 从 0 开始,0 为小寒)
|
|
50
|
+
* @param n 0-23
|
|
51
|
+
*/
|
|
52
|
+
declare const getSolarTerm: (n: number) => string;
|
|
53
|
+
/**
|
|
54
|
+
* 返回公历 y 年 m 月的天数(会自动处理闰年)
|
|
55
|
+
* @param y 公历年
|
|
56
|
+
* @param m 公历月(1-12)
|
|
57
|
+
* @return 28-31
|
|
58
|
+
*/
|
|
59
|
+
declare const solarDays: (y: number, m: number) => number;
|
|
60
|
+
/**
|
|
61
|
+
* 返回公历 y 年 m 月 1 日是星期几
|
|
62
|
+
* @param y 公历年
|
|
63
|
+
* @param m 公历月(1-12)
|
|
64
|
+
* @return 0-6,0 为周日
|
|
65
|
+
*/
|
|
66
|
+
declare const solarFirstWeek: (y: number, m: number) => number;
|
|
67
|
+
/**
|
|
68
|
+
* 返回公历 y 年 m 月第 nth 个星期 weekday 是几号
|
|
69
|
+
* @param y 公历年
|
|
70
|
+
* @param m 公历月(1-12)
|
|
71
|
+
* @param weekday 0-6,0 为周日
|
|
72
|
+
* @param nth 第几个,从 1 开始
|
|
73
|
+
* @example nthWeekdayOfMonth(2026, 5, 0, 2) // 10,2026 年母亲节是 5 月 10 日
|
|
74
|
+
*/
|
|
75
|
+
declare const nthWeekdayOfMonth: (y: number, m: number, weekday: number, nth: number) => number;
|
|
76
|
+
/**
|
|
77
|
+
* 公历月、日判断所属星座
|
|
78
|
+
* @param m 公历月(1-12)
|
|
79
|
+
* @param d 公历日
|
|
80
|
+
* @example toAstro(4, 19) // "白羊座"
|
|
81
|
+
*/
|
|
82
|
+
declare const toAstro: (m: number, d: number) => string;
|
|
83
|
+
/**
|
|
84
|
+
* 传入公历年获得该年第 n 个节气所在公历月的日期
|
|
85
|
+
* @param y 公历年(1900-2100)
|
|
86
|
+
* @param n 第几个节气(1-24),1 为小寒
|
|
87
|
+
* @return 日期数字
|
|
88
|
+
* @example getTerm(1987, 3) // 4,1987 年 2 月 4 日立春
|
|
89
|
+
*/
|
|
90
|
+
declare const getTerm: (y: number, n: number) => number;
|
|
91
|
+
/**
|
|
92
|
+
* 年份转生肖,以农历年为准
|
|
93
|
+
* @param y 年份
|
|
94
|
+
* @example getAnimal(1987) // "兔"
|
|
95
|
+
*/
|
|
96
|
+
declare const getAnimal: (y: number) => string;
|
|
97
|
+
/**
|
|
98
|
+
* 数字转中文,0-10
|
|
99
|
+
* @param num 0-10
|
|
100
|
+
* @example toChinaNum(3) // "三"
|
|
101
|
+
*/
|
|
102
|
+
declare const toChinaNum: (num: number) => string;
|
|
103
|
+
/**
|
|
104
|
+
* 公历节日 / 农历节日的映射表
|
|
105
|
+
* key 为四位 "MMDD",value 为节日名称数组
|
|
106
|
+
*/
|
|
107
|
+
type FestivalMap = Record<string, string[]>;
|
|
108
|
+
/**
|
|
109
|
+
* 节日配置,sFtv 为公历节日,lFtv 为农历节日
|
|
110
|
+
*/
|
|
111
|
+
interface FestivalConfig {
|
|
112
|
+
/** 公历节日,key 为 MMDD,例如 { "0101": ["元旦"] } */
|
|
113
|
+
sFtv?: FestivalMap;
|
|
114
|
+
/** 农历节日,key 为 MMDD,例如 { "0101": ["春节"] } */
|
|
115
|
+
lFtv?: FestivalMap;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 单年的放假与调休配置(用户注入时的形态,两个数组都可省略)
|
|
119
|
+
*/
|
|
120
|
+
interface RestEntry {
|
|
121
|
+
/** 该年放假日(MMDD),不含普通周末 */
|
|
122
|
+
xiu?: string[];
|
|
123
|
+
/** 该年调休补班日(MMDD),一般是周末上班 */
|
|
124
|
+
ban?: string[];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 归一化之后的单年配置:两个数组一定存在,内部查询用
|
|
128
|
+
*/
|
|
129
|
+
interface NormalizedRestEntry {
|
|
130
|
+
xiu: string[];
|
|
131
|
+
ban: string[];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 调休配置,key 为年份,value 为该年的放假/补班日
|
|
135
|
+
*/
|
|
136
|
+
type RestConfig = Record<string | number, RestEntry>;
|
|
137
|
+
/**
|
|
138
|
+
* getHolidays() 的返回值:结构完整,可直接再传给 createCalendar()
|
|
139
|
+
*/
|
|
140
|
+
interface HolidaySnapshot {
|
|
141
|
+
setFestival: {
|
|
142
|
+
sFtv: FestivalMap;
|
|
143
|
+
lFtv: FestivalMap;
|
|
144
|
+
};
|
|
145
|
+
setRest: Record<string, NormalizedRestEntry>;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* createCalendar 的入参
|
|
149
|
+
*/
|
|
150
|
+
interface HolidayConfig {
|
|
151
|
+
setFestival?: FestivalConfig;
|
|
152
|
+
setRest?: RestConfig;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* createCalendar 的选项
|
|
156
|
+
*/
|
|
157
|
+
interface SetHolidayOptions {
|
|
158
|
+
/** 为 true 时丢弃内置节日/调休数据,只使用传入的数据 */
|
|
159
|
+
replace?: boolean;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 公历转农历 / 农历转公历的完整结果
|
|
163
|
+
*/
|
|
164
|
+
interface LunarResult {
|
|
165
|
+
/** 是否在 rest.json 的放假日列表(xiu)中;与周末无关 */
|
|
166
|
+
xiu: boolean;
|
|
167
|
+
/** 是否在 rest.json 的调休补班日列表(ban)中 */
|
|
168
|
+
ban: boolean;
|
|
169
|
+
/** 公历节日,例如 ["元旦"];没有节日时是共享的只读空数组 */
|
|
170
|
+
gljr: readonly string[];
|
|
171
|
+
/** 农历节日,例如 ["春节"];没有节日时是共享的只读空数组 */
|
|
172
|
+
nljr: readonly string[];
|
|
173
|
+
/** 农历年 */
|
|
174
|
+
lYear: number;
|
|
175
|
+
/** 农历月,1-12 */
|
|
176
|
+
lMonth: number;
|
|
177
|
+
/** 农历日,1-30 */
|
|
178
|
+
lDay: number;
|
|
179
|
+
/** 生肖,以农历年为准 */
|
|
180
|
+
animal: string;
|
|
181
|
+
/** 农历月中文名,例如 "正月"、"闰四月" */
|
|
182
|
+
lMonthCn: string;
|
|
183
|
+
/** 农历日中文名,例如 "初一" */
|
|
184
|
+
lDayCn: string;
|
|
185
|
+
/** 公历年 */
|
|
186
|
+
cYear: number;
|
|
187
|
+
/** 公历月,1-12 */
|
|
188
|
+
cMonth: number;
|
|
189
|
+
/** 公历日 */
|
|
190
|
+
cDay: number;
|
|
191
|
+
/** 干支年,以立春为界,与 gzMonth 口径一致 */
|
|
192
|
+
gzYear: string;
|
|
193
|
+
/** 干支年,以正月初一为界,与 animal 口径一致 */
|
|
194
|
+
gzYearLunar: string;
|
|
195
|
+
/** 干支月,以节气为界 */
|
|
196
|
+
gzMonth: string;
|
|
197
|
+
/** 干支日 */
|
|
198
|
+
gzDay: string;
|
|
199
|
+
/** 当天十二个时辰的干支 */
|
|
200
|
+
gzHour: string[];
|
|
201
|
+
/** 是否今天(按本地时区) */
|
|
202
|
+
isToday: boolean;
|
|
203
|
+
/** 是否闰月 */
|
|
204
|
+
isLeap: boolean;
|
|
205
|
+
/** 星期数字,1-7,周一为 1、周日为 7 */
|
|
206
|
+
nWeek: number;
|
|
207
|
+
/** 星期数字,0-6,周日为 0,与 solarFirstWeek 口径一致 */
|
|
208
|
+
dayOfWeek: number;
|
|
209
|
+
/** 星期中文,例如 "星期日" */
|
|
210
|
+
ncWeek: string;
|
|
211
|
+
/** 节气名,当天不是节气时为 null */
|
|
212
|
+
term: string | null;
|
|
213
|
+
/** 星座,例如 "摩羯座" */
|
|
214
|
+
astro: string;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* getHolidays 的选项
|
|
218
|
+
*/
|
|
219
|
+
interface GetHolidaysOptions {
|
|
220
|
+
/** 默认 true:返回合并内置数据后的完整配置;false:只返回创建实例时传入的那部分 */
|
|
221
|
+
merged?: boolean;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* 固定了一份节假日配置的日历实例
|
|
225
|
+
*
|
|
226
|
+
* 由 createCalendar() 创建,配置在创建时固定,实例之间互不影响。
|
|
227
|
+
*/
|
|
228
|
+
interface Calendar {
|
|
229
|
+
/** 公历转农历,不传参返回今天 */
|
|
230
|
+
solarToLunar(this: void, y?: number, m?: number, d?: number): LunarResult;
|
|
231
|
+
/** 农历转公历 */
|
|
232
|
+
lunarToSolar(this: void, y: number, m: number, d: number, isLeapMonth?: boolean): LunarResult;
|
|
233
|
+
/** 该实例当前配置的深拷贝,可再次用于 createCalendar() */
|
|
234
|
+
getHolidays(this: void, options?: GetHolidaysOptions): HolidaySnapshot;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* 创建固定节假日配置的日历实例
|
|
238
|
+
*
|
|
239
|
+
* 不读取也不修改任何全局状态;配置在创建时校验并冻结,
|
|
240
|
+
* 多个实例之间互不影响。不传配置时使用内置数据。
|
|
241
|
+
*
|
|
242
|
+
* @param config 节假日 / 调休配置
|
|
243
|
+
* @param options replace 为 true 时忽略内置数据
|
|
244
|
+
* @throws TypeError 配置格式不合法(含具体字段路径)
|
|
245
|
+
* @example
|
|
246
|
+
* const cc = createCalendar({ setRest: { 2027: { xiu: ["0101"] } } });
|
|
247
|
+
* cc.solarToLunar(2027, 1, 1).xiu; // true
|
|
248
|
+
*/
|
|
249
|
+
declare const createCalendar: (config?: HolidayConfig, options?: SetHolidayOptions) => Calendar;
|
|
250
|
+
declare const utils: {
|
|
251
|
+
lYearDays: typeof lYearDays;
|
|
252
|
+
leapMonth: typeof leapMonth;
|
|
253
|
+
leapDays: typeof leapDays;
|
|
254
|
+
lMonthDays: typeof lMonthDays;
|
|
255
|
+
toChinaMonth: typeof toChinaMonth;
|
|
256
|
+
toChinaDay: typeof toChinaDay;
|
|
257
|
+
toChinaNum: typeof toChinaNum;
|
|
258
|
+
solarDays: typeof solarDays;
|
|
259
|
+
solarFirstWeek: typeof solarFirstWeek;
|
|
260
|
+
nthWeekdayOfMonth: typeof nthWeekdayOfMonth;
|
|
261
|
+
toAstro: typeof toAstro;
|
|
262
|
+
getAnimal: typeof getAnimal;
|
|
263
|
+
getTerm: typeof getTerm;
|
|
264
|
+
getSolarTerm: typeof getSolarTerm;
|
|
265
|
+
toGanZhi: typeof toGanZhi;
|
|
266
|
+
toGanZhiYear: typeof toGanZhiYear;
|
|
267
|
+
toHourGanZhi: typeof toHourGanZhi;
|
|
268
|
+
};
|
|
269
|
+
export { type Calendar, type FestivalConfig, type FestivalMap, type GetHolidaysOptions, type HolidayConfig, type HolidaySnapshot, type LunarResult, type RestConfig, type RestEntry, type SetHolidayOptions, createCalendar, createCalendar as default, utils };
|