Skip to content

Navigation Menu

Sign in
Sign up

cmpopts: add EquateApproxDuration - #396

Open
knQzx wants to merge 1 commit into
google:master from
knQzx:feat/equate-approx-duration
Open

cmpopts: add EquateApproxDuration #396
knQzx wants to merge 1 commit into
google:master from
knQzx:feat/equate-approx-duration

Conversation

@knQzx

@knQzx knQzx commented Jul 20, 2026

Copy link
Copy Markdown

adds EquateApproxDuration, a Comparer option that treats two time.Duration values as equal when they are within a given margin. it is the direct analog of EquateApproxTime but for raw durations rather than time.Time

the comparison normalizes order and checks the margin with !(x+a.margin < y) instead of subtracting, so it stays correct when the gap between the two values would overflow time.Duration, there is a MaxInt64 vs MinInt64 case covering that

no FilterValues wrapper here since unlike time.Time there is no zero-value special casing for durations. following the existing convention i did not add a runnable example, EquateApprox and EquateApproxTime have none either

fixes #394

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

cmpopts: add EquateApproxDuration

1 participant

AltStyle によって変換されたページ (->オリジナル) /