Repository navigation
Conversation
between counts a negative difference from the earlier date and negates it, which keeps between(a, b) == -between(b, a) but not a + between(a, b) == b for a > b (64512 of the 266815 such pairs of days in 2015-2016 fail). Document the guarantee that holds. Refs nim-lang#26825 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…irections between(a, b) counts a negative difference from the earlier date, so a + between(a, b) != b for some a > b (nim-lang#26825). anchoredBetween counts from startDt in either direction and returns a distinct AnchoredInterval without unary `-`, because negating a calendar difference does not lead back to the anchor. It holds a + anchoredBetween(a, b) == b for all 534361 ordered pairs of days in 2015-2016 (UTC) and for 602176 pairs of times 30 minutes apart around DST changes in each of Europe/Stockholm, America/Belem, America/New_York and Australia/Lord_Howe, also with endDt in UTC. This commit only adds API and can be dropped from the PR on its own. Refs nim-lang#26825 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
-1 from me. Your own code can easily use a helper modules that contains |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #26825.
between(a, b)counts a negative difference from the earlier date and negates it. That keepsbetween(a, b) == -between(b, a)(the runnable example) but breaks the documentedstartDt + between(startDt, endDt) == endDtfor somea > b: 64512 of the 266815 such pairs of days in 2015-2016. The two properties cannot both hold (see the issue for jiff and dateutil), so:anchoredBetween(startDt, endDt)counts fromstartDtin either direction and returnsAnchoredInterval, a distinctTimeIntervalwithout unary-. Months are counted first, then days instartDt.timezone, and the rest as an exact duration, sostartDt + anchoredBetween(startDt, endDt) == endDtholds, also when the timezones differ.No existing proc answers this:
between(lib/pure/times.nim) is the only calendar difference intimes, and it normalizesendDt < startDtto-between(endDt, startDt)by design.Testing:
tests/stdlib/ttimes.nim(c refc/orc, js with and without jsbigint64): month ends and leap days in both directions, the example from std/times: between(a, b) does not round-trip when a > b, although the doc guarantees a + between(a, b) == b #26825, and times around DST changes in Europe/Stockholm and America/Belem, also againstendDt.utc.a + anchoredBetween(a, b) == bfor all 534361 ordered pairs of days in 2015-2016 (UTC), and for 602176 pairs of times 30 minutes apart around DST changes in each of Europe/Stockholm, America/Belem, America/New_York and Australia/Lord_Howe; 0 failures.🤖 Generated with Claude Code