Add FormatLayout() method enabling custom date formatting using Go's
standard layout format (Mon Jan 2 15:04:05 MST 2006) with full
internationalization support for month and weekday names.
Key features:
- Custom layout strings using Go's time.Format() reference date
- i18n support for EN and DE languages
- Translates both full and abbreviated month/weekday names
- Fast path for EN (direct passthrough, ~144-173 ns/op)
- Optimized replacements using strings.NewReplacer (~7.3-7.5 µs/op for DE)
- Comprehensive test coverage (97.6%)
Implementation:
- Added FormatLayout() method to format.go
- Uses strings.NewReplacer for atomic replacements to avoid substring collisions
- Added 280+ lines of tests covering all months, weekdays, and edge cases
- Added 4 benchmark tests (all meet <10µs target)
- Added 4 example tests demonstrating usage
Performance:
- EN (fast path): ~144-173 ns/op
- DE (with i18n): ~7.3-7.5 µs/op
- Both well under <10µs requirement
Files changed:
- format.go: Added FormatLayout() method with full godoc
- format_test.go: Added comprehensive tests and benchmarks
- example_test.go: Added 4 example functions
Add Format type with preset constants (ISO, EU, US, Long, RFC2822) and
Format() method for convenient date formatting.
Key features:
- Type-safe Format enum with 5 preset formats
- ISO (2026-02-09), EU (09.02.2026), US (02/09/2026)
- Long format with i18n support (EN: "February 9, 2026", DE: "9. Februar 2026")
- RFC2822 email format
- Language-independent formats (ISO, EU, US, RFC2822) ignore Lang setting
- Language-dependent Long format respects WithLang()
Implementation:
- format.go: Format type, constants, Format() method, formatLong() helper
- format_test.go: 26 tests covering all formats, edge cases, immutability
- example_test.go: 8 example functions demonstrating usage
Performance (exceeds targets):
- ISO/EU/US: ~90 ns (target: <5 µs)
- RFC2822: ~207 ns (target: <5 µs)
- Long EN/DE: ~270 ns (target: <10 µs)
All tests pass with comprehensive coverage of leap years, month boundaries,
and language dependency.