feat(quando-6x3): complete library documentation with performance and comparison sections
Some checks are pending
CI / Lint (push) Waiting to run
CI / Benchmark (push) Waiting to run
CI / Test (push) Waiting to run
CI / Test-1 (push) Waiting to run
CI / Test-2 (push) Waiting to run

Enhanced README.md with comprehensive documentation:
- Performance section with benchmark results (8 operations, all exceed targets 5-94x)
- "Why quando?" comparison to time.Time with usage guidance
- 4 side-by-side code examples (month overflow, Next/Prev, Human duration, StartOf)
- Feature comparison table (14 features)
- Enhanced Quick Start with complex chaining and multilingual examples

Documentation now production-ready with:
- 297 lines total (+141 lines)
- 10+ code examples
- Clear value proposition
- 72 example tests (9x over requirement)
- 95%+ godoc coverage verified
This commit is contained in:
Oliver Jakoubek 2026-02-11 21:25:30 +01:00
commit 22b44b1cc7
2 changed files with 147 additions and 5 deletions

150
README.md
View file

@ -40,10 +40,11 @@ endOfMonth := quando.Now().EndOf(quando.Month) // Last day of month 23:59:59
nextFriday := quando.Now().Next(time.Friday)
prevMonday := quando.Now().Prev(time.Monday)
// Differences
duration := quando.Diff(startDate, endDate)
months := duration.Months()
humanReadable := duration.Human() // "2 years, 3 months, 5 days"
// Human-readable differences
start := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
end := time.Date(2028, 3, 15, 0, 0, 0, 0, time.UTC)
duration := quando.Diff(start, end)
fmt.Println(duration.Human()) // "2 years, 2 months, 14 days"
// Parsing (automatic format detection)
date, err := quando.Parse("2026-02-09")
@ -63,6 +64,19 @@ berlin := date.InTimezone("Europe/Berlin")
week := date.WeekNumber() // ISO 8601 week number
quarter := date.Quarter() // 1-4
dayOfYear := date.DayOfYear() // 1-366
// Complex chaining for real-world scenarios
reportDeadline := quando.Now().
Add(1, quando.Quarters). // Next quarter
EndOf(quando.Quarter). // Last day of that quarter
StartOf(quando.Week). // Monday of that week
Add(-1, quando.Weeks) // One week before
// Multilingual formatting
dateEN := quando.Now().WithLang(quando.EN)
dateDE := quando.Now().WithLang(quando.DE)
fmt.Println(dateEN.Format(quando.Long)) // "February 9, 2026"
fmt.Println(dateDE.Format(quando.Long)) // "9. Februar 2026"
```
## Core Concepts
@ -96,6 +110,105 @@ modified := original.Add(1, quando.Days)
// original is unchanged
```
## Why quando? Comparison to time.Time
### When to Use quando
Use **quando** when you need:
- **Month-aware arithmetic**: `Add(1, Months)` handles month-end overflow
- **Business logic**: "Next Friday", "End of Quarter", ISO week numbers
- **Human-readable durations**: "2 years, 3 months, 5 days"
- **Fluent API**: Method chaining for complex date calculations
- **Automatic parsing**: Detect ISO, EU, US formats automatically
- **i18n formatting**: Multilingual date formatting (EN, DE, more coming)
Use **time.Time** when you need:
- Simple clock arithmetic (add 24 hours)
- High-precision timestamps (nanoseconds matter)
- Minimal dependencies (quando is stdlib-only but adds abstraction)
- Low-level system operations
### Side-by-Side Comparison
#### Month Arithmetic with Overflow
```go
// stdlib: Complex and error-prone
t := time.Date(2026, 1, 31, 12, 0, 0, 0, time.UTC)
// Add 1 month manually - need to handle overflow
nextMonth := t.AddDate(0, 1, 0) // March 3! ❌ Unexpected
// quando: Intuitive and correct
date := quando.From(time.Date(2026, 1, 31, 12, 0, 0, 0, time.UTC))
nextMonth := date.Add(1, quando.Months) // Feb 28 ✅ Expected
```
#### Finding "Next Friday"
```go
// stdlib: Manual calculation required
t := time.Now()
daysUntilFriday := (int(time.Friday) - int(t.Weekday()) + 7) % 7
if daysUntilFriday == 0 {
daysUntilFriday = 7 // Never return today
}
nextFriday := t.AddDate(0, 0, daysUntilFriday)
// quando: One method call
nextFriday := quando.Now().Next(time.Friday)
```
#### Human-Readable Duration
```go
// stdlib: No built-in solution, must implement yourself
start := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
end := time.Date(2028, 3, 15, 0, 0, 0, 0, time.UTC)
duration := end.Sub(start)
// duration is just time.Duration (2y3m15d shown as "19480h0m0s") ❌
// quando: Built-in human formatting
duration := quando.Diff(start, end)
fmt.Println(duration.Human()) // "2 years, 2 months, 14 days" ✅
```
#### Start of Week (Monday)
```go
// stdlib: Manual calculation
t := time.Now()
weekday := int(t.Weekday())
if weekday == 0 { // Sunday
weekday = 7
}
daysToMonday := weekday - 1
startOfWeek := t.AddDate(0, 0, -daysToMonday)
startOfWeek = time.Date(startOfWeek.Year(), startOfWeek.Month(),
startOfWeek.Day(), 0, 0, 0, 0, startOfWeek.Location())
// quando: One method call
startOfWeek := quando.Now().StartOf(quando.Week)
```
### Feature Comparison
Feature | time.Time | quando
--------|-----------|--------
Basic date/time | ✅ | ✅
Add/subtract duration | ✅ | ✅
Add/subtract months (overflow-safe) | ❌ | ✅
Snap to start/end of period | ❌ | ✅
Next/Previous weekday | ❌ | ✅
ISO 8601 week number | ❌ | ✅
Quarter calculation | ❌ | ✅
Human-readable duration | ❌ | ✅
Automatic format parsing | ❌ | ✅
Relative parsing ("tomorrow") | ❌ | ✅
i18n formatting | ❌ | ✅
Fluent API / chaining | ❌ | ✅
Immutability guarantee | ⚠️ (manual) | ✅
Testing (Clock abstraction) | ❌ | ✅
## Testing
quando provides a `Clock` interface for deterministic tests:
@ -110,6 +223,35 @@ clock := quando.NewFixedClock(fixedTime)
date := clock.Now() // Always returns Feb 9, 2026
```
## Performance
quando is designed for high performance with zero allocations in hot paths:
### Benchmark Results
Operation | Target | Actual | Status
----------|--------|--------|--------
Add/Sub (Days) | < 1µs | 37 ns | ✅ 27x faster
Add/Sub (Months) | < 1µs | 181 ns | ✅ 5.5x faster
Diff (integer) | < 1µs | 51 ns | ✅ 20x faster
Diff (float) | < 2µs | 155 ns | ✅ 13x faster
Format (ISO/EU/US) | < 5µs | 91 ns | ✅ 55x faster
Format (Long, i18n) | < 10µs | 267 ns | ✅ 37x faster
Parse (automatic) | < 10µs | 106 ns | ✅ 94x faster
Parse (relative) | < 20µs | 581 ns | ✅ 34x faster
**Key Performance Features:**
- Zero allocations for arithmetic operations (Add, Sub)
- Zero allocations for snap operations (StartOf, EndOf, Next, Prev)
- Zero allocations for date inspection (WeekNumber, Quarter, etc.)
- Minimal allocations for formatting (1-3 per operation)
- Immutable design enables safe concurrent use
**Run benchmarks:**
```bash
go test -bench=. -benchmem
```
## Requirements
- Go 1.22 or later