[repo-assist] feat: add TimeSpan interop — Add(TimeSpan), operator+ and operator-#18
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
Add natural .NET TimeSpan interoperability to DateTimeNano: - DateTimeNano.Add(TimeSpan) — shift by a TimeSpan, negative allowed - operator+(DateTimeNano, TimeSpan) — shift forward - operator-(DateTimeNano, TimeSpan) — shift back Implementation delegates to the existing AddNanoseconds(long) method (TimeSpan.Ticks * 100 = nanoseconds), so overflow/underflow protection is fully inherited. TimeSpan precision is 100 ns (one tick); sub-tick nanoseconds on the DateTimeNano side are unaffected by the addition. This complements operator-(DateTimeNano, DateTimeNano) and mirrors the ergonomics of System.DateTime (DateTime + TimeSpan, DateTime - TimeSpan), allowing idiomatic .NET duration arithmetic alongside DataBento-style nanosecond offsets. 4 new tests added; all 44 tests pass on net8.0. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
11 tasks
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.
🤖 This pull request was created by Repo Assist, an automated AI assistant.
Summary
Add natural .NET
TimeSpaninteroperability toDateTimeNano:DateTimeNano.Add(TimeSpan)— shift a timestamp by aTimeSpanoperator +(DateTimeNano, TimeSpan)— shift forwardoperator -(DateTimeNano, TimeSpan)— shift backRationale
System.DateTimesupports+/-withTimeSpanout of the box, and many .NET APIs return durations asTimeSpan. Adding the same operators toDateTimeNanomakes the two types easier to use together:Before:
After:
The operators complement the existing
operator -(DateTimeNano, DateTimeNano) → longand the pendingoperator +(DateTimeNano, long)/operator -(DateTimeNano, long)in PR #15.Implementation notes
AddNanoseconds(long)(TimeSpan.Ticks * 100converts ticks → nanoseconds). Overflow/underflow protection is fully inherited.TimeSpanprecision is 100 ns (one tick); sub-tick nanoseconds stored inDateTimeNanoare unaffected.Test Status
✅ 44 tests pass on
net8.0(40 original + 4 new tests coveringAdd(TimeSpan)and both operators for positive and negative durations). Build succeeded for net8.0, net9.0, and net10.0 with 0 warnings.