time/TEST.md

27 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Test Report: @go/time
## 📋 测试概览
- **测试时间**: 2026-04-22
- **测试环境**: darwin/amd64 (Intel i9-9980HK)
- **Go 版本**: 1.25.0
## ✅ 功能测试 (Functional Tests)
| 场景 | 状态 | 描述 |
| :--- | :--- | :--- |
| `TestParse` | PASS | 覆盖时间戳、紧凑格式、RFC3339、标准/斜杠/点日期、短年份、中文格式、纯时间等。 |
| `TestFormat` | PASS | 验证直观布局 (YYYY-MM-DD HH:mm:ss) 的正确转换与格式化。 |
| `TestAdd` | PASS | 验证 DSL 时间加减 (+1Y-2M+3D, +1h30m 等) 的逻辑。 |
| `TestHelpers` | PASS | 验证 `Now()`, `Today()`, `Yesterday()`, `Tomorrow()` 辅助函数。 |
## 🛡️ 鲁棒性防御 (Robustness)
- **非法输入拦截**:空字符串或无效格式均返回 `time.Now()`,确保业务不中断,无 Panic。
- **自动时区修正**RFC3339/JS 格式自动转换为 `time.Local`,保持时区一致性。
- **中文宽松匹配**支持“下午3点”、“15时”等多种中文习惯。
## ⚡ 性能基准 (Benchmarks)
| 函数 | 平均耗时 | 性能分析 |
| :--- | :--- | :--- |
| `Parse` | **501.1 ns/op** | 灵活的多格式探测解析,性能保持在微秒级。 |
| `Format` | **742.6 ns/op** | 包含布局字符串替换与 Go 原生 Format性能良好。 |
| `Add` | **146.2 ns/op** | DSL 解析与时间计算极其高效。 |