dsh-usage-peak 1.1.0 → 1.2.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/CHANGELOG.md +8 -0
- package/README.md +7 -1
- package/client.js +74 -2
- package/holidays.js +75 -0
- package/index.js +34 -4
- package/package.json +3 -2
- package/test/core.test.js +42 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
- 峰谷判断接入中国大陆节假日/调休日历:法定节假日全天谷时,调休上班日(含周末)按工作日峰谷计算。
|
|
6
|
+
- 新增 `holidays.js`(2026 年国务院办公厅安排,与 holiday-cn 交叉核对);缺失年份回落到周一至周五,并在面板给出 `calendar-missing` 提示。
|
|
7
|
+
- 趋势图 tooltip 标注节假日名称。
|
|
8
|
+
- 面板新增页脚:GitHub 仓库超链接(引导 Star)、当前版本号、日历覆盖年份。
|
|
9
|
+
- 快照新增 `version` / `repo` / `calendar` 字段,版本号由 `package.json` 单一来源读取。
|
|
10
|
+
|
|
3
11
|
## 1.1.0
|
|
4
12
|
|
|
5
13
|
- 新增 7 / 14 / 30 天统计窗口切换,接口支持 `?days=`(白名单校验,快照按窗口分别缓存)。
|
package/README.md
CHANGED
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
- **近 7 / 14 / 30 天趋势**:右上角切换窗口,按天堆叠柱状,缺数据的日期补零,列数恒定;可对照峰时占比判断"贵在哪天"。
|
|
21
21
|
- **按模型**:Flash / Pro 各自的请求数、tokens、花费。
|
|
22
22
|
- **价目表**:当前时段那一行高亮,方便解释账单。
|
|
23
|
+
- **节假日与调休**:按国务院办公厅公布的安排判断——法定节假日全天谷时,调休上班的周末按工作日峰谷计算;当前覆盖 2026 年,缺失年份会在面板给出提示并回落到周一至周五规则。
|
|
24
|
+
- **页脚**:GitHub 仓库链接(可顺手点个 Star)、当前版本号与日历覆盖年份。
|
|
23
25
|
|
|
24
26
|
设置页里的入口是「用量仪表盘」,侧栏胶囊就是同一份数据的浓缩版。
|
|
25
27
|
|
|
@@ -32,7 +34,9 @@
|
|
|
32
34
|
| DeepSeek Flash | 0.02 / 0.04 | 1 / 2 | 4 / 8 |
|
|
33
35
|
| DeepSeek Pro | 0.15 / 0.30 | 4.5 / 9 | 13.5 / 27 |
|
|
34
36
|
|
|
35
|
-
峰时 =
|
|
37
|
+
峰时 = 工作日 09:00–12:00、14:00–18:00(北京时间);其余时间、周末与法定节假日为谷时,单价减半。调休上班日(包括周末)按工作日的峰谷窗口计算。
|
|
38
|
+
|
|
39
|
+
节假日数据在 [`holidays.js`](holidays.js),来源为[国务院办公厅 2026 年放假安排通知](https://www.gov.cn/zhengce/zhengceku/202511/content_7047091.htm),并与 [holiday-cn](https://github.com/NateScarlet/holiday-cn) 交叉核对。新一年安排公布后,补一组日期并把年份加进 `CALENDAR_YEARS` 即可。
|
|
36
40
|
|
|
37
41
|
## 数据来源
|
|
38
42
|
|
|
@@ -82,6 +86,8 @@ A usage and cost dashboard for DeepSeek Harness. It reads the local session logs
|
|
|
82
86
|

|
|
83
87
|
|
|
84
88
|
- a persistent sidebar pill with peak/valley state, today's spend, tokens and the countdown to the next price switch;
|
|
89
|
+
- China public holidays and makeup workdays: holidays are valley all day, makeup weekend workdays follow the weekday windows (2026 calendar shipped; missing years fall back to Mon-Fri with a visible warning);
|
|
90
|
+
- a footer with the GitHub repository link, the running version and the covered calendar years;
|
|
85
91
|
- a details page (Settings → Usage dashboard) with KPIs, an hourly breakdown, cost composition, a 7/14/30-day trend switch, a per-model table and the price list;
|
|
86
92
|
- a "valley saving" KPI: since peak costs exactly 2x valley, moving the same peak usage to valley time would have saved half of the peak spend.
|
|
87
93
|
|
package/client.js
CHANGED
|
@@ -52,6 +52,9 @@ window.__ModuleLoader__.load({
|
|
|
52
52
|
'unit.calls': '次',
|
|
53
53
|
'unit.minute': '分',
|
|
54
54
|
'warn.unknownModel': '未识别的模型按 Flash 价计算',
|
|
55
|
+
'warn.calendarMissing': '以下年份还没有节假日数据,峰谷按周一至周五计算:',
|
|
56
|
+
'footer.calendar': '峰谷已计入节假日与调休:',
|
|
57
|
+
'footer.star': '给个 Star',
|
|
55
58
|
'range.7': '近 7 天',
|
|
56
59
|
'range.14': '近 14 天',
|
|
57
60
|
'range.30': '近 30 天',
|
|
@@ -123,6 +126,9 @@ window.__ModuleLoader__.load({
|
|
|
123
126
|
'unit.calls': 'req',
|
|
124
127
|
'unit.minute': 'm',
|
|
125
128
|
'warn.unknownModel': 'Unknown models are priced as Flash',
|
|
129
|
+
'warn.calendarMissing': 'No holiday data for these years, peak hours fall back to Mon-Fri:',
|
|
130
|
+
'footer.calendar': 'Peak hours include holidays and makeup workdays:',
|
|
131
|
+
'footer.star': 'Star it',
|
|
126
132
|
'range.7': 'Last 7 days',
|
|
127
133
|
'range.14': 'Last 14 days',
|
|
128
134
|
'range.30': 'Last 30 days',
|
|
@@ -514,7 +520,7 @@ window.__ModuleLoader__.load({
|
|
|
514
520
|
h(
|
|
515
521
|
'div',
|
|
516
522
|
{
|
|
517
|
-
title: `${entry.day} · ${yuan(entry.cost)} · ${entry.calls} ${props.t('unit.calls')}`,
|
|
523
|
+
title: `${entry.day}${entry.holiday ? ` · ${entry.holiday}` : ''} · ${yuan(entry.cost)} · ${entry.calls} ${props.t('unit.calls')}`,
|
|
518
524
|
style: {
|
|
519
525
|
flex: 1,
|
|
520
526
|
width: '100%',
|
|
@@ -721,7 +727,9 @@ window.__ModuleLoader__.load({
|
|
|
721
727
|
? warning
|
|
722
728
|
: warning.code === 'unknown-model'
|
|
723
729
|
? `${t('warn.unknownModel')}: ${(warning.models || []).join(', ')}`
|
|
724
|
-
:
|
|
730
|
+
: warning.code === 'calendar-missing'
|
|
731
|
+
? `${t('warn.calendarMissing')} ${(warning.years || []).join(' / ')}`
|
|
732
|
+
: String(warning.code || warning),
|
|
725
733
|
),
|
|
726
734
|
),
|
|
727
735
|
),
|
|
@@ -880,6 +888,70 @@ window.__ModuleLoader__.load({
|
|
|
880
888
|
),
|
|
881
889
|
),
|
|
882
890
|
body,
|
|
891
|
+
h(
|
|
892
|
+
'footer',
|
|
893
|
+
{
|
|
894
|
+
style: {
|
|
895
|
+
marginTop: 2,
|
|
896
|
+
paddingTop: 10,
|
|
897
|
+
borderTop: `1px solid ${C.border}`,
|
|
898
|
+
display: 'flex',
|
|
899
|
+
alignItems: 'center',
|
|
900
|
+
justifyContent: 'space-between',
|
|
901
|
+
gap: 10,
|
|
902
|
+
flexWrap: 'wrap',
|
|
903
|
+
fontSize: 10.5,
|
|
904
|
+
color: C.text3,
|
|
905
|
+
},
|
|
906
|
+
},
|
|
907
|
+
h(
|
|
908
|
+
'span',
|
|
909
|
+
null,
|
|
910
|
+
data && data.calendar && data.calendar.years && data.calendar.years.length
|
|
911
|
+
? `${t('footer.calendar')} ${data.calendar.years.join(' / ')}`
|
|
912
|
+
: '',
|
|
913
|
+
),
|
|
914
|
+
h(
|
|
915
|
+
'div',
|
|
916
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' } },
|
|
917
|
+
h(
|
|
918
|
+
'a',
|
|
919
|
+
{
|
|
920
|
+
href: (data && data.repo) || 'https://github.com/hhse/dsh-usage-peak',
|
|
921
|
+
target: '_blank',
|
|
922
|
+
rel: 'noopener noreferrer',
|
|
923
|
+
title: 'https://github.com/hhse/dsh-usage-peak',
|
|
924
|
+
style: {
|
|
925
|
+
color: C.text2,
|
|
926
|
+
textDecoration: 'none',
|
|
927
|
+
fontWeight: 500,
|
|
928
|
+
display: 'inline-flex',
|
|
929
|
+
alignItems: 'center',
|
|
930
|
+
gap: 5,
|
|
931
|
+
},
|
|
932
|
+
},
|
|
933
|
+
'⭐',
|
|
934
|
+
'github.com/hhse/dsh-usage-peak',
|
|
935
|
+
h('span', { style: { color: C.peak, fontWeight: 600 } }, `· ${t('footer.star')}`),
|
|
936
|
+
),
|
|
937
|
+
data && data.version
|
|
938
|
+
? h(
|
|
939
|
+
'span',
|
|
940
|
+
{
|
|
941
|
+
style: {
|
|
942
|
+
padding: '1px 6px',
|
|
943
|
+
borderRadius: 6,
|
|
944
|
+
border: `1px solid ${C.border}`,
|
|
945
|
+
background: C.layer2,
|
|
946
|
+
color: C.text2,
|
|
947
|
+
fontVariantNumeric: 'tabular-nums',
|
|
948
|
+
},
|
|
949
|
+
},
|
|
950
|
+
`v${data.version}`,
|
|
951
|
+
)
|
|
952
|
+
: null,
|
|
953
|
+
),
|
|
954
|
+
),
|
|
883
955
|
);
|
|
884
956
|
}
|
|
885
957
|
|
package/holidays.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mainland China public holidays and makeup workdays.
|
|
3
|
+
*
|
|
4
|
+
* Peak pricing only applies on working days; a public holiday is billed at the
|
|
5
|
+
* valley tariff all day, while a makeup workday ("调休上班", including a
|
|
6
|
+
* weekend) follows the normal weekday peak windows.
|
|
7
|
+
*
|
|
8
|
+
* Source: State Council notice
|
|
9
|
+
* https://www.gov.cn/zhengce/zhengceku/202511/content_7047091.htm
|
|
10
|
+
* Cross-checked against NateScarlet/holiday-cn (2026.json), which cites the
|
|
11
|
+
* same notice.
|
|
12
|
+
*
|
|
13
|
+
* To support a new year, append its dates here and add the year to
|
|
14
|
+
* CALENDAR_YEARS. Years without data fall back to the weekday rule and raise a
|
|
15
|
+
* `calendar-missing` warning in the snapshot.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** Years covered by the data below. */
|
|
19
|
+
export const CALENDAR_YEARS = [2026];
|
|
20
|
+
|
|
21
|
+
/** Public holidays: date -> name. Billed at the valley tariff all day. */
|
|
22
|
+
export const OFF_DAYS = new Map([
|
|
23
|
+
['2026-01-01', '元旦'],
|
|
24
|
+
['2026-01-02', '元旦'],
|
|
25
|
+
['2026-01-03', '元旦'],
|
|
26
|
+
['2026-02-15', '春节'],
|
|
27
|
+
['2026-02-16', '春节'],
|
|
28
|
+
['2026-02-17', '春节'],
|
|
29
|
+
['2026-02-18', '春节'],
|
|
30
|
+
['2026-02-19', '春节'],
|
|
31
|
+
['2026-02-20', '春节'],
|
|
32
|
+
['2026-02-21', '春节'],
|
|
33
|
+
['2026-02-22', '春节'],
|
|
34
|
+
['2026-02-23', '春节'],
|
|
35
|
+
['2026-04-04', '清明节'],
|
|
36
|
+
['2026-04-05', '清明节'],
|
|
37
|
+
['2026-04-06', '清明节'],
|
|
38
|
+
['2026-05-01', '劳动节'],
|
|
39
|
+
['2026-05-02', '劳动节'],
|
|
40
|
+
['2026-05-03', '劳动节'],
|
|
41
|
+
['2026-05-04', '劳动节'],
|
|
42
|
+
['2026-05-05', '劳动节'],
|
|
43
|
+
['2026-06-19', '端午节'],
|
|
44
|
+
['2026-06-20', '端午节'],
|
|
45
|
+
['2026-06-21', '端午节'],
|
|
46
|
+
['2026-09-25', '中秋节'],
|
|
47
|
+
['2026-09-26', '中秋节'],
|
|
48
|
+
['2026-09-27', '中秋节'],
|
|
49
|
+
['2026-10-01', '国庆节'],
|
|
50
|
+
['2026-10-02', '国庆节'],
|
|
51
|
+
['2026-10-03', '国庆节'],
|
|
52
|
+
['2026-10-04', '国庆节'],
|
|
53
|
+
['2026-10-05', '国庆节'],
|
|
54
|
+
['2026-10-06', '国庆节'],
|
|
55
|
+
['2026-10-07', '国庆节'],
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
/** Makeup workdays: date -> the holiday they belong to. */
|
|
59
|
+
export const WORKDAYS = new Map([
|
|
60
|
+
['2026-01-04', '元旦'],
|
|
61
|
+
['2026-02-14', '春节'],
|
|
62
|
+
['2026-02-28', '春节'],
|
|
63
|
+
['2026-05-09', '劳动节'],
|
|
64
|
+
['2026-09-20', '国庆节'],
|
|
65
|
+
['2026-10-10', '国庆节'],
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
/** Calendar year of a `YYYY-MM-DD` day key, as a number. */
|
|
69
|
+
export function yearOf(dayKey) {
|
|
70
|
+
return Number(String(dayKey).slice(0, 4));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function hasCalendar(year) {
|
|
74
|
+
return CALENDAR_YEARS.includes(Number(year));
|
|
75
|
+
}
|
package/index.js
CHANGED
|
@@ -14,7 +14,11 @@ import os from 'node:os';
|
|
|
14
14
|
import path from 'node:path';
|
|
15
15
|
import zlib from 'node:zlib';
|
|
16
16
|
|
|
17
|
+
import { CALENDAR_YEARS, OFF_DAYS, WORKDAYS, hasCalendar, yearOf } from './holidays.js';
|
|
18
|
+
|
|
17
19
|
const NS = 'dsh-usage-peak';
|
|
20
|
+
const REPO_URL = 'https://github.com/hhse/dsh-usage-peak';
|
|
21
|
+
const VERSION = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version;
|
|
18
22
|
const ROUTE_BASE = '/plugin/dsh-usage-peak';
|
|
19
23
|
const SNAPSHOT_TTL_MS = 15_000;
|
|
20
24
|
const BJ_OFFSET = 8 * 60 * 60 * 1000;
|
|
@@ -43,11 +47,18 @@ export function dayKey(ts) {
|
|
|
43
47
|
return bjDate(ts).toISOString().slice(0, 10);
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Peak = Beijing Mon-Fri 09:00-12:00 and 14:00-18:00; everything else is valley
|
|
52
|
+
* (half price). Public holidays are valley all day, makeup workdays (including
|
|
53
|
+
* a Saturday/Sunday) follow the weekday windows.
|
|
54
|
+
*/
|
|
47
55
|
export function isPeakAt(ts) {
|
|
56
|
+
const key = dayKey(ts);
|
|
57
|
+
if (OFF_DAYS.has(key)) return false;
|
|
48
58
|
const d = bjDate(ts);
|
|
49
59
|
const dow = d.getUTCDay();
|
|
50
|
-
|
|
60
|
+
const weekend = dow === 0 || dow === 6;
|
|
61
|
+
if (weekend && !WORKDAYS.has(key)) return false;
|
|
51
62
|
const minutes = d.getUTCHours() * 60 + d.getUTCMinutes();
|
|
52
63
|
return (minutes >= 540 && minutes < 720) || (minutes >= 840 && minutes < 1080);
|
|
53
64
|
}
|
|
@@ -60,8 +71,10 @@ export function nextSwitch(ts) {
|
|
|
60
71
|
const da = d.getUTCDate();
|
|
61
72
|
for (let k = 0; k < 9; k += 1) {
|
|
62
73
|
const probe = new Date(Date.UTC(y, mo, da + k));
|
|
74
|
+
const key = probe.toISOString().slice(0, 10);
|
|
75
|
+
if (OFF_DAYS.has(key)) continue;
|
|
63
76
|
const dow = probe.getUTCDay();
|
|
64
|
-
if (dow === 0 || dow === 6) continue;
|
|
77
|
+
if ((dow === 0 || dow === 6) && !WORKDAYS.has(key)) continue;
|
|
65
78
|
for (const hour of [9, 12, 14, 18]) {
|
|
66
79
|
const at = Date.UTC(probe.getUTCFullYear(), probe.getUTCMonth(), probe.getUTCDate(), hour, 0, 0) - BJ_OFFSET;
|
|
67
80
|
if (at > ts) return { at, status: hour === 9 || hour === 14 ? 'peak' : 'valley' };
|
|
@@ -289,6 +302,7 @@ export function shapeDay(day) {
|
|
|
289
302
|
// Peak is exactly 2x valley, so moving these peak tokens to valley saves half.
|
|
290
303
|
savingIfValley: round(day.peakCost / 2),
|
|
291
304
|
peakShare: day.cost > 0 ? day.peakCost / day.cost : 0,
|
|
305
|
+
holiday: OFF_DAYS.get(day.day) || null,
|
|
292
306
|
hitRate: billable > 0 ? day.cacheTokens / billable : 0,
|
|
293
307
|
avgTokens: day.calls > 0 ? Math.round(tokens / day.calls) : 0,
|
|
294
308
|
firstAt: day.firstAt,
|
|
@@ -311,6 +325,16 @@ export function hoursOf(day) {
|
|
|
311
325
|
}));
|
|
312
326
|
}
|
|
313
327
|
|
|
328
|
+
/** Calendar years touched by the window that have no holiday data yet. */
|
|
329
|
+
function missingCalendarYears(window) {
|
|
330
|
+
const years = new Set();
|
|
331
|
+
for (const entry of window) {
|
|
332
|
+
const year = yearOf(entry.day);
|
|
333
|
+
if (!hasCalendar(year)) years.add(year);
|
|
334
|
+
}
|
|
335
|
+
return years.size > 0 ? [{ code: 'calendar-missing', years: [...years] }] : [];
|
|
336
|
+
}
|
|
337
|
+
|
|
314
338
|
/**
|
|
315
339
|
* Pure aggregation over decoded turns.
|
|
316
340
|
*
|
|
@@ -394,7 +418,10 @@ export function aggregateTurns(turns, options = {}) {
|
|
|
394
418
|
avgTokensPerCall: week.calls > 0 ? Math.round(week.tokens / week.calls) : 0,
|
|
395
419
|
},
|
|
396
420
|
models,
|
|
397
|
-
warnings:
|
|
421
|
+
warnings: [
|
|
422
|
+
...(unknownModels.size > 0 ? [{ code: 'unknown-model', models: [...unknownModels] }] : []),
|
|
423
|
+
...missingCalendarYears(window),
|
|
424
|
+
],
|
|
398
425
|
};
|
|
399
426
|
}
|
|
400
427
|
|
|
@@ -421,6 +448,9 @@ export function buildSnapshot(options = {}) {
|
|
|
421
448
|
ok: true,
|
|
422
449
|
generatedAt: now,
|
|
423
450
|
tz: 'Asia/Shanghai',
|
|
451
|
+
version: VERSION,
|
|
452
|
+
repo: REPO_URL,
|
|
453
|
+
calendar: { years: CALENDAR_YEARS, holidays: OFF_DAYS.size, workdays: WORKDAYS.size },
|
|
424
454
|
windowDays: days,
|
|
425
455
|
now: {
|
|
426
456
|
ts: now,
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-usage-peak",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "DeepSeek Harness
|
|
5
|
+
"description": "DeepSeek Harness 用量峰谷仪表盘:峰/谷时段(含节假日与调休)、今日花费与 tokens、7/14/30 天窗口、缓存命中、谷时更省,侧栏常驻胶囊 + 设置页详情。",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./index.js",
|
|
8
8
|
"./client": "./client.js",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"index.js",
|
|
14
14
|
"client.js",
|
|
15
|
+
"holidays.js",
|
|
15
16
|
"cordis.patch.yml",
|
|
16
17
|
"locale/*.json",
|
|
17
18
|
"icon.svg",
|
package/test/core.test.js
CHANGED
|
@@ -41,6 +41,48 @@ test('isPeakAt covers the four weekday windows and nothing else', () => {
|
|
|
41
41
|
assert.equal(isPeakAt(bj(2026, 11, 8, 15, 0)), false);
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
+
test('public holidays are valley all day, makeup workdays follow weekday hours', () => {
|
|
45
|
+
// 2026 National Day: Oct 1 (Thu) is a public holiday.
|
|
46
|
+
assert.equal(isPeakAt(bj(2026, 10, 1, 10, 0)), false);
|
|
47
|
+
assert.equal(isPeakAt(bj(2026, 10, 7, 15, 0)), false);
|
|
48
|
+
// Spring Festival makeup: Feb 14 is a Saturday but a working day.
|
|
49
|
+
assert.equal(isPeakAt(bj(2026, 2, 14, 10, 0)), true);
|
|
50
|
+
assert.equal(isPeakAt(bj(2026, 2, 14, 13, 0)), false);
|
|
51
|
+
// New Year makeup: Jan 4 is a Sunday but a working day.
|
|
52
|
+
assert.equal(isPeakAt(bj(2026, 1, 4, 10, 0)), true);
|
|
53
|
+
// A plain weekend stays valley.
|
|
54
|
+
assert.equal(isPeakAt(bj(2026, 11, 7, 10, 0)), false);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('nextSwitch skips holiday blocks and honors makeup workdays', () => {
|
|
58
|
+
// Wednesday Sep 30 2026 evening: Oct 1-7 are holidays, next peak is Oct 8.
|
|
59
|
+
const afterNationalDay = nextSwitch(bj(2026, 9, 30, 19, 0));
|
|
60
|
+
assert.equal(afterNationalDay.at, bj(2026, 10, 8, 9, 0));
|
|
61
|
+
assert.equal(afterNationalDay.status, 'peak');
|
|
62
|
+
|
|
63
|
+
// Saturday Sep 19: Sunday Sep 20 is a makeup workday, so it is the next peak.
|
|
64
|
+
const makeup = nextSwitch(bj(2026, 9, 19, 10, 0));
|
|
65
|
+
assert.equal(makeup.at, bj(2026, 9, 20, 9, 0));
|
|
66
|
+
assert.equal(makeup.status, 'peak');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('aggregateTurns tags holiday days in the window', () => {
|
|
70
|
+
const now = bj(2026, 10, 7, 12, 0);
|
|
71
|
+
const agg = aggregateTurns([], { now, days: 7 });
|
|
72
|
+
assert.equal(agg.window[0].day, '2026-10-01');
|
|
73
|
+
assert.equal(agg.window[0].holiday, '国庆节');
|
|
74
|
+
assert.equal(agg.window[6].holiday, '国庆节');
|
|
75
|
+
assert.deepEqual(agg.warnings, []);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('years without calendar data fall back to weekdays and warn', () => {
|
|
79
|
+
const now = bj(2027, 1, 5, 12, 0);
|
|
80
|
+
// 2027-10-01 is a Friday; without data the weekday rule marks it peak.
|
|
81
|
+
assert.equal(isPeakAt(bj(2027, 10, 1, 10, 0)), true);
|
|
82
|
+
const agg = aggregateTurns([], { now, days: 7 });
|
|
83
|
+
assert.deepEqual(agg.warnings, [{ code: 'calendar-missing', years: [2027] }]);
|
|
84
|
+
});
|
|
85
|
+
|
|
44
86
|
test('nextSwitch walks to the next boundary and reports the target status', () => {
|
|
45
87
|
const lunch = nextSwitch(bj(2026, 11, 9, 12, 30));
|
|
46
88
|
assert.equal(lunch.status, 'peak');
|