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
…54)

Fixes issue 52.

(cherry picked from commit 2cb7183)
  • Loading branch information
ararslan authored Nov 30, 2022
1 parent d798ede commit d3fc779
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.2.10"
version = "0.2.11"

[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 @@ -365,7 +365,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 @@ -188,6 +188,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 d3fc779

@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/73199

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.2.11 -m "<description of version>" d3fc779c4ba79994b85a115dd9733d4f13b7cfe9
git push origin v0.2.11

Please sign in to comment.