Skip to content

Commit 8799e49

Browse files
fix: resolveTimeRange 中 --from/--to 优先于 --last (#8)
--last 有默认值导致显式传入的 --from/--to 被忽略, 调整判断顺序使 --from/--to 优先生效,影响 11 个命令。
1 parent 435e870 commit 8799e49

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'octo-cli': patch
3+
---
4+
5+
修复 --from/--to 参数被 --last 默认值覆盖的问题
6+
7+
- resolveTimeRange 中 --from/--to 优先级提升至 --last 之前
8+
- 修复 alerts search、issues search、trace search 等 11 个命令的时间范围参数失效问题

src/time.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,14 @@ describe('resolveTimeRange', () => {
5858
expect(from).toBe(new Date('2024-01-01T00:00:00Z').getTime());
5959
expect(to).toBe(new Date('2024-01-01T01:00:00Z').getTime());
6060
});
61+
62+
it('--from/--to takes precedence over --last', () => {
63+
const { from, to } = resolveTimeRange({
64+
last: '1h',
65+
from: '2024-06-01T00:00:00Z',
66+
to: '2024-06-01T23:59:59Z',
67+
});
68+
expect(from).toBe(new Date('2024-06-01T00:00:00Z').getTime());
69+
expect(to).toBe(new Date('2024-06-01T23:59:59Z').getTime());
70+
});
6171
});

src/time.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ export function resolveTimeRange(opts: {
2929
}): { from: number; to: number } {
3030
const now = Date.now();
3131

32-
if (opts.last) {
33-
const ms = parseDuration(opts.last);
34-
return { from: now - ms, to: now };
35-
}
36-
3732
if (opts.from) {
3833
const from = parseTimestamp(opts.from);
3934
const to = opts.to ? parseTimestamp(opts.to) : now;
4035
return { from, to };
4136
}
4237

38+
if (opts.last) {
39+
const ms = parseDuration(opts.last);
40+
return { from: now - ms, to: now };
41+
}
42+
4343
// Default: last 15 minutes
4444
return { from: now - 15 * 60_000, to: now };
4545
}

0 commit comments

Comments
 (0)