Intuitive and idiomatic date calculations for Go
go
Find a file
Oliver Jakoubek 889e78da90 feat(quando-r1o): consolidate benchmarks and achieve 99.5% test coverage
Reorganized test suite with consolidated benchmarks and comprehensive
edge case coverage, exceeding 95% minimum coverage requirement.

Changes:
- Created benchmark_test.go with all 52 benchmarks organized by category
  (arithmetic, clock, date, diff, format, inspection, parse, snap, unit)
- Removed benchmarks from 9 individual test files for better organization
- Added 6 edge case tests to improve coverage:
  * Format() unknown type fallback
  * formatLong() empty lang default
  * Format.String() unknown value
  * isYearPrefix() edge cases
  * StartOf()/EndOf() unsupported units
- Added 3 DST transition tests:
  * Spring forward (23-hour day)
  * Fall back (25-hour day)
  * Multiple timezone preservation

Results:
- Test coverage: 97.7% → 99.5% (exceeds 95% target)
- All 52 benchmarks consolidated and verified
- All benchmarks meet performance targets
- No test regressions

Files modified:
- Created: benchmark_test.go (580 lines)
- Modified: 9 test files (removed benchmarks, added tests)
2026-02-11 21:13:09 +01:00
.beads feat(quando-r1o): consolidate benchmarks and achieve 99.5% test coverage 2026-02-11 21:13:09 +01:00
.github/workflows feat(quando-91w): initialize project structure and tooling 2026-02-11 16:28:14 +01:00
.gitattributes feat(quando-91w): initialize project structure and tooling 2026-02-11 16:28:14 +01:00
.gitignore feat(quando-91w): initialize project structure and tooling 2026-02-11 16:28:14 +01:00
AGENTS.md feat(quando-91w): initialize project structure and tooling 2026-02-11 16:28:14 +01:00
arithmetic.go feat(quando-b4r): implement Add and Sub arithmetic operations 2026-02-11 17:43:03 +01:00
arithmetic_test.go feat(quando-r1o): consolidate benchmarks and achieve 99.5% test coverage 2026-02-11 21:13:09 +01:00
benchmark_test.go feat(quando-r1o): consolidate benchmarks and achieve 99.5% test coverage 2026-02-11 21:13:09 +01:00
CLAUDE.md feat(quando-91w): initialize project structure and tooling 2026-02-11 16:28:14 +01:00
clock.go feat(quando-vih): implement Clock abstraction for testability 2026-02-11 16:33:23 +01:00
clock_test.go feat(quando-r1o): consolidate benchmarks and achieve 99.5% test coverage 2026-02-11 21:13:09 +01:00
date.go feat(quando-zbr): implement i18n infrastructure for EN/DE languages 2026-02-11 19:27:16 +01:00
date_test.go feat(quando-r1o): consolidate benchmarks and achieve 99.5% test coverage 2026-02-11 21:13:09 +01:00
diff.go feat(quando-10t): implement human-readable duration format with i18n support 2026-02-11 19:42:10 +01:00
diff_test.go feat(quando-r1o): consolidate benchmarks and achieve 99.5% test coverage 2026-02-11 21:13:09 +01:00
errors.go feat(quando-36t): implement error types and handling 2026-02-11 17:40:01 +01:00
errors_test.go feat(quando-36t): implement error types and handling 2026-02-11 17:40:01 +01:00
example_test.go feat(quando-7m5): implement MustParse convenience function 2026-02-11 20:54:32 +01:00
format.go feat(quando-95w): implement custom layout formatting with i18n support 2026-02-11 20:34:57 +01:00
format_test.go feat(quando-r1o): consolidate benchmarks and achieve 99.5% test coverage 2026-02-11 21:13:09 +01:00
go.mod chore: update module name to code.beautifulmachines.dev/jakoubek/quando 2026-02-11 17:25:25 +01:00
i18n.go feat(quando-zbr): implement i18n infrastructure for EN/DE languages 2026-02-11 19:27:16 +01:00
i18n_test.go feat(quando-zbr): implement i18n infrastructure for EN/DE languages 2026-02-11 19:27:16 +01:00
inspect.go feat(quando-5ib): implement date inspection methods 2026-02-11 20:45:53 +01:00
inspect_test.go feat(quando-r1o): consolidate benchmarks and achieve 99.5% test coverage 2026-02-11 21:13:09 +01:00
LICENSE feat(quando-91w): initialize project structure and tooling 2026-02-11 16:28:14 +01:00
parse.go feat(quando-7m5): implement MustParse convenience function 2026-02-11 20:54:32 +01:00
parse_test.go feat(quando-r1o): consolidate benchmarks and achieve 99.5% test coverage 2026-02-11 21:13:09 +01:00
PRD.md feat(quando-91w): initialize project structure and tooling 2026-02-11 16:28:14 +01:00
quando.go feat(quando-j2s): implement core Date type and conversions 2026-02-11 16:31:21 +01:00
README.md docs: update module path in README to include jakoubek namespace 2026-02-11 17:25:43 +01:00
snap.go feat(quando-9sf): implement Next and Prev weekday navigation 2026-02-11 17:33:54 +01:00
snap_test.go feat(quando-r1o): consolidate benchmarks and achieve 99.5% test coverage 2026-02-11 21:13:09 +01:00
unit.go feat(quando-4bh): implement Unit type and constants 2026-02-11 16:34:42 +01:00
unit_test.go feat(quando-r1o): consolidate benchmarks and achieve 99.5% test coverage 2026-02-11 21:13:09 +01:00

quando

Intuitive and idiomatic date calculations for Go

quando is a standalone Go library for complex date operations that are cumbersome or impossible with the Go standard library alone. It provides a fluent API for date arithmetic, parsing, formatting, and timezone-aware calculations.

Features

  • Fluent API: Chain operations naturally: quando.Now().Add(2, Months).StartOf(Week)
  • Month-End Aware: Handles edge cases like Jan 31 + 1 month = Feb 28
  • DST Safe: Calendar-based arithmetic (not clock-based)
  • Zero Dependencies: Only Go stdlib
  • Immutable: Thread-safe by design
  • i18n Ready: Multilingual formatting (EN, DE in Phase 1)
  • Testable: Built-in Clock abstraction for deterministic tests

Installation

go get code.beautifulmachines.dev/jakoubek/quando

Quick Start

import "code.beautifulmachines.dev/jakoubek/quando"

// Get current date
now := quando.Now()

// Date arithmetic with month-end handling
date := quando.From(time.Date(2026, 1, 31, 0, 0, 0, 0, time.UTC))
result := date.Add(1, quando.Months) // Feb 28, 2026 (not overflow)

// Snap to boundaries
monday := quando.Now().StartOf(quando.Week)     // This week's Monday 00:00
endOfMonth := quando.Now().EndOf(quando.Month)  // Last day of month 23:59:59

// Next/Previous dates
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"

// Parsing (automatic format detection)
date, err := quando.Parse("2026-02-09")
date, err := quando.Parse("09.02.2026")       // EU format
date, err := quando.Parse("3 days ago")       // Relative

// Formatting
date.Format(quando.ISO)      // "2026-02-09"
date.Format(quando.Long)     // "February 9, 2026"
date.FormatLayout("02 Jan")  // "09 Feb"

// Timezone conversion
utc := date.InTimezone("UTC")
berlin := date.InTimezone("Europe/Berlin")

// Date inspection
week := date.WeekNumber()       // ISO 8601 week number
quarter := date.Quarter()       // 1-4
dayOfYear := date.DayOfYear()   // 1-366

Core Concepts

Month-End Overflow Handling

When adding months, if the target day doesn't exist, quando snaps to the last valid day:

jan31 := quando.From(time.Date(2026, 1, 31, 0, 0, 0, 0, time.UTC))
feb28 := jan31.Add(1, quando.Months) // Feb 28, not March 3

DST-Aware Arithmetic

Adding days means "same time on next calendar day", not "24 hours later":

// During DST transition (23-hour day)
date := quando.From(time.Date(2026, 3, 31, 2, 0, 0, 0, cetLocation))
next := date.Add(1, quando.Days) // April 1, 2:00 CEST (not 3:00)

Immutability

All operations return new instances. Original values are never modified:

original := quando.Now()
modified := original.Add(1, quando.Days)
// original is unchanged

Testing

quando provides a Clock interface for deterministic tests:

// In production
date := quando.Now()

// In tests
fixedTime := time.Date(2026, 2, 9, 12, 0, 0, 0, time.UTC)
clock := quando.NewFixedClock(fixedTime)
date := clock.Now() // Always returns Feb 9, 2026

Requirements

  • Go 1.22 or later
  • No external dependencies

Documentation

Full documentation available at: pkg.go.dev/code.beautifulmachines.dev/jakoubek/quando

License

MIT License - see LICENSE file for details.

Contributing

Contributions welcome! Please ensure:

  • Tests pass (go test ./...)
  • Code is formatted (go fmt ./...)
  • No vet warnings (go vet ./...)
  • Coverage ≥95% for new code

Roadmap

Phase 1 (Current)

  • Project setup
  • 🚧 Core date operations
  • 🚧 Parsing and formatting
  • 🚧 Timezone handling
  • 🚧 i18n (EN, DE)

Phase 2

  • Date ranges and series
  • Batch operations
  • Performance optimizations

Phase 3

  • Holiday calendars
  • Business day calculations
  • Extended language support

Acknowledgments

Inspired by Moment.js, Carbon, and date-fns, but designed to be idiomatic Go.