@ysgroup/core 0.1.35 → 0.1.36
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/package.json +1 -1
- package/src/calendar.ts +17 -4
- package/src/index.ts +2 -0
package/package.json
CHANGED
package/src/calendar.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { ysLunar, type YsLunarDate } from "./lunar";
|
|
12
12
|
|
|
13
|
-
/** workday 工作日、weekend 周末、holiday 放假、adjusted
|
|
13
|
+
/** workday 工作日、weekend 周末、holiday 放假、adjusted 法定补班(调休上班的周末)。 */
|
|
14
14
|
export type YsDayKind = "workday" | "weekend" | "holiday" | "adjusted";
|
|
15
15
|
|
|
16
16
|
/** 一天的信息(服务端 ys_base.calendar 的 DayInfo.to_dict,covered=false 表示这一年还没有放假安排)。 */
|
|
@@ -112,9 +112,12 @@ export const YS_DAY_KIND_LABELS: Record<YsDayKind, string> = {
|
|
|
112
112
|
workday: "工作日",
|
|
113
113
|
weekend: "周末",
|
|
114
114
|
holiday: "放假",
|
|
115
|
-
adjusted: "
|
|
115
|
+
adjusted: "法定补班",
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
+
/** 期货夜盘从这一天起才有(2013-07-05 上期所首开夜盘,和服务端 ys_base.calendar 的 NIGHT_SESSION_START 一致);更早的交易日不说「无夜盘」。 */
|
|
119
|
+
export const YS_NIGHT_SESSION_START = "2013-07-05";
|
|
120
|
+
|
|
118
121
|
const DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
119
122
|
const MONTH_RE = /^(\d{4})-(\d{2})$/;
|
|
120
123
|
const DAY_MS = 86_400_000;
|
|
@@ -225,6 +228,13 @@ export function ysMonthTitle(month: string): string {
|
|
|
225
228
|
return match ? `${match[1]} 年 ${Number(match[2])} 月` : "";
|
|
226
229
|
}
|
|
227
230
|
|
|
231
|
+
/** 「10 月 1 日 周四」(同一年里说某一天,如夜盘计入哪个交易日)。 */
|
|
232
|
+
export function ysShortDateTitle(date: string): string {
|
|
233
|
+
const match = DATE_RE.exec(date);
|
|
234
|
+
if (!match || !ysIsDate(date)) return "";
|
|
235
|
+
return `${Number(match[2])} 月 ${Number(match[3])} 日 ${ysWeekdayLabel(date)}`;
|
|
236
|
+
}
|
|
237
|
+
|
|
228
238
|
/** 「2026 年 10 月 1 日 周四」。 */
|
|
229
239
|
export function ysDateTitle(date: string): string {
|
|
230
240
|
const match = DATE_RE.exec(date);
|
|
@@ -344,15 +354,17 @@ export interface YsMonthSummary {
|
|
|
344
354
|
complete: boolean;
|
|
345
355
|
workdays: number;
|
|
346
356
|
trading: number;
|
|
347
|
-
/**
|
|
357
|
+
/** 休市天数(含周末、放假日、法定补班的周末)。 */
|
|
348
358
|
closed: number;
|
|
349
359
|
holidays: number;
|
|
350
360
|
adjusted: number;
|
|
351
361
|
/** 交易所额外休市天数(国务院安排是工作日)。 */
|
|
352
362
|
marketClosed: number;
|
|
363
|
+
/** 当晚有期货夜盘的交易日数。 */
|
|
364
|
+
night: number;
|
|
353
365
|
}
|
|
354
366
|
|
|
355
|
-
/**
|
|
367
|
+
/** 一个月的工作日、交易日、休市、放假、法定补班、交易所额外休市和夜盘天数。 */
|
|
356
368
|
export function ysMonthSummary(
|
|
357
369
|
days: readonly YsCalendarDay[],
|
|
358
370
|
month: string,
|
|
@@ -371,6 +383,7 @@ export function ysMonthSummary(
|
|
|
371
383
|
holidays: count((item) => item.kind === "holiday"),
|
|
372
384
|
adjusted: count((item) => item.kind === "adjusted"),
|
|
373
385
|
marketClosed: count((item) => Boolean(item.market_closed)),
|
|
386
|
+
night: count((item) => Boolean(item.trading) && item.night_session === true),
|
|
374
387
|
};
|
|
375
388
|
}
|
|
376
389
|
|
package/src/index.ts
CHANGED
|
@@ -121,6 +121,7 @@ export {
|
|
|
121
121
|
export {
|
|
122
122
|
YS_CALENDAR_SOURCE_LABELS,
|
|
123
123
|
YS_DAY_KIND_LABELS,
|
|
124
|
+
YS_NIGHT_SESSION_START,
|
|
124
125
|
YS_TRADING_TAG_LABELS,
|
|
125
126
|
YS_WEEKDAY_LABELS,
|
|
126
127
|
ysAddDays,
|
|
@@ -135,6 +136,7 @@ export {
|
|
|
135
136
|
ysMonthSummary,
|
|
136
137
|
ysMonthTitle,
|
|
137
138
|
ysShiftMonth,
|
|
139
|
+
ysShortDateTitle,
|
|
138
140
|
ysToday,
|
|
139
141
|
ysTradingMarks,
|
|
140
142
|
ysDayDetail,
|