Closed
feat: 改进时间显示格式,支持相对时间 #128
aflyingtoAdd on Apr 5Closed at Apr 7
aflyingto
Apr 7 Comments:
Apr 7 Comments:
阶段记录
- 阶段: ready-for-review
- 结论: PR #95 已为
gc issue list、gc issue view、gc pr view增加--time-format absolute|relative,并补齐帮助、文档和错误路径验证;issue 128 进入独立执行主体评审。 - 证据:
- 关联 PR: !95
- 提交:
bce2821 feat: complete issue output contracts and view details - 验证:
go test ./...、go build -o ./gc ./cmd/gc - 实际命令:
./gc issue list -R infra-test/gctest1 --limit 1 --time-format relative、./gc issue view 7 -R infra-test/gctest1 --time-format relative、./gc pr view 1 -R infra-test/gctest1 --time-format relative - 错误路径:
./gc issue view 1 --time-format yaml、./gc pr view 1 -R infra-test/gctest1 --time-format yaml返回稳定用法错误
- 下一步: 等待独立执行主体评审;如需要支持任意自定义 layout,再单独设计新的输入契约。
开发进度
- 根因: 现有时间展示固定为绝对时间,且 issue/pr view 与 list 没有统一的文本时间策略。
- 主要修改: 引入共享时间格式解析与渲染,统一
absolute|relative语义。 - 测试:
go test ./... - 实际命令验证: 同上
- 安全影响: 无认证、权限或危险写路径变更
- 风险或未覆盖项: 本次未支持 issue 提案中的任意自定义时间 layout,只保留
absolute|relative两个稳定值。 - 关联 PR: !95


aflyingto
Apr 7 Comments:
Apr 7 Comments:
aflyingto
May 1 Comments:
May 1 Comments:
问题描述
当前时间显示格式固定为
2006-01-02 15:04,对于用户来说不够友好。建议方案
--time-format选项示例
# 默认相对时间 $ gc issue list #123 open 修复登录问题 (2 hours ago) # 绝对时间 $ gc issue list --time-format absolute #123 open 修复登录问题 (2026-04-05 18:00) # 自定义格式 $ gc issue list --time-format "2006-01-02" #123 open 修复登录问题 (2026-04-05)实现方案
func FormatTime(t time.Time, format string) string { switch format { case "relative": return humanize.Time(t) case "absolute": return t.Format("2006-01-02 15:04") default: return t.Format(format) } }推荐库
github.com/dustin/go-humanize- 相对时间优先级
中