feat(quando-4bh): implement Unit type and constants

- Define Unit type as int for type-safe time unit constants
- Implement all 8 unit constants (Seconds through Years) using iota
- Add String() method for debugging and error messages
- Comprehensive unit tests verifying constants, ordering, and comparability
- Type safety tests demonstrating compile-time safety
- Example tests showing usage patterns
- 100% test coverage (exceeds 95% requirement)

All acceptance criteria met:
✓ Unit type defined as int
✓ All 8 unit constants defined (Seconds through Years)
✓ Units use iota for ordering
✓ Godoc comments for Unit type and constants
✓ Unit tests verifying constants
This commit is contained in:
Oliver Jakoubek 2026-02-11 16:34:42 +01:00
commit 1be52c7e91
4 changed files with 241 additions and 2 deletions

View file

@ -112,3 +112,38 @@ func ExampleFixedClock_deterministic() {
// Date 2: 2026-02-09 12:00:00
// Same: true
}
// ExampleUnit demonstrates the Unit type
func ExampleUnit() {
// Units are used with Add, Sub, StartOf, EndOf operations
units := []quando.Unit{
quando.Seconds,
quando.Minutes,
quando.Hours,
quando.Days,
quando.Weeks,
quando.Months,
quando.Quarters,
quando.Years,
}
for _, u := range units {
fmt.Println(u.String())
}
// Output:
// seconds
// minutes
// hours
// days
// weeks
// months
// quarters
// years
}
// ExampleUnit_String demonstrates the String method
func ExampleUnit_String() {
unit := quando.Days
fmt.Printf("Unit: %s\n", unit)
// Output: Unit: days
}