Files
commerce/util/timeutil/timediff.go
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

23 lines
349 B
Go

package timeutil
import (
"time"
)
func YearMonthDiff(t1, t2 time.Time) (years, months int) {
t2 = t2.AddDate(0, 0, 1) // advance t2 to make the range inclusive
years = 0
for t1.AddDate(years, 0, 0).Before(t2) {
years++
}
years--
months = 0
for t1.AddDate(years, months, 0).Before(t2) {
months++
}
months--
return years, months
}