Skip to content

Commit

Permalink
Handle empty spans in invert_spans (#48) (#49)
Browse files Browse the repository at this point in the history
(cherry picked from commit 97d628f)
  • Loading branch information
ararslan authored Oct 12, 2022
1 parent e9ec7a5 commit d798ede
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
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.9"
version = "0.2.10"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
1 change: 1 addition & 0 deletions src/TimeSpans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ Return a vector of `TimeSpan`s representing the gaps between the spans in the
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)
merge_spans!((a, b) -> start(b) <= stop(a), spans)
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ end
i_spans = invert_spans(spans, parent_span)
@test length(i_spans) == 6
@test all(duration.(i_spans) .== Second(8))

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

@testset "broadcast_spans" begin
Expand Down

2 comments on commit d798ede

@ararslan
Copy link
Member Author

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/70050

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.10 -m "<description of version>" d798ede6f0a04616e8f1f9e47a2055af15db46a7
git push origin v0.2.10

Please sign in to comment.