Skip to content

Commit

Permalink
Allow spans that cross the parent's boundary in invert_spans (#53)
Browse files Browse the repository at this point in the history
Fixes issue 52.
  • Loading branch information
ararslan authored Nov 30, 2022
1 parent 9829236 commit 2cb7183
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TimeSpans"
uuid = "bb34ddd2-327f-4c4a-bfb0-c98fc494ece1"
authors = ["Beacon Biosignals, Inc."]
version = "0.3.5"
version = "0.3.6"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
2 changes: 1 addition & 1 deletion src/TimeSpans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ iterable `spans` that are contained within `parent_span`.
function invert_spans(spans, parent_span)
isempty(spans) && return [TimeSpan(parent_span)]
spans = collect(spans)
filter!(x -> contains(parent_span, x), spans)
filter!(x -> overlaps(x, parent_span), spans)
merge_spans!((a, b) -> start(b) <= stop(a), spans)
gaps = TimeSpan[]
previous_span = first(spans)
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ end

# empty
@test invert_spans(TimeSpan[], parent_span) == [parent_span]

# some spans cross the parent span's boundary
i_spans = invert_spans([TimeSpan(-5, 3), TimeSpan(6, 8)], TimeSpan(0, 10))
@test i_spans == [TimeSpan(3, 6), TimeSpan(8, 10)]
end

@testset "broadcast_spans" begin
Expand Down

2 comments on commit 2cb7183

@hannahilea
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/73193

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.6 -m "<description of version>" 2cb71834926428c5f13b1ea9b85cc2ff582130b2
git push origin v0.3.6

Please sign in to comment.