Skip to content

Commit 5139a70

Browse files
committed
tweak check
1 parent 576c1d9 commit 5139a70

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/interop.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,26 @@ function stop_index_from_time(sample_rate, interval::Interval{Nanosecond,Closed,
7979
# `time_from_index(sample_rate, last_index + 1)` gives us the _start_ of the next sample
8080
# we subtract 1 ns to get the (inclusive) _end_ of the span associated to this sample
8181
end_of_span_time = time_from_index(sample_rate, last_index + 1) - Nanosecond(1)
82-
# if this end isn't fully included in the interval, then we need to go back one
83-
if !(end_of_span_time in interval)
82+
# if this end isn't fully included in the interval, then we need to go back one.
83+
# Note: we don't use `end_of_span_time in interval`, since that could occur if we are before
84+
# the _start_ of the interval, rather than past the end of it.
85+
if !(end_of_span_time <= last(interval))
8486
@debug "Decrementing last index to fully fit within span"
8587
last_index -= 1
8688
end
8789

8890
# We should never need to decrement twice, but we will assert this
8991
end_of_span_time = time_from_index(sample_rate, last_index + 1) - Nanosecond(1)
90-
if !(end_of_span_time in interval)
92+
if !(end_of_span_time <= last(interval))
9193
msg = """
9294
[AlignedSpans] Unexpected error in `stop_index_from_time` with `RoundFullyContainedSampleSpans`:
9395
9496
- `sample_rate = $(sample_rate)`
9597
- `interval = $(interval)`
9698
- `mode = $(mode)`
9799
- `end_of_span_time = $(end_of_span_time)`
98-
- `interval = $(interval)`
99-
- Expected `end_of_span_time in interval`
100+
- `last(interval) = $(last(interval))`
101+
- Expected `end_of_span_time <= last(interval)`
100102
101103
Please file an issue on AlignedSpans.jl: https://github.com/beacon-biosignals/AlignedSpans.jl/issues/new
102104
"""

0 commit comments

Comments
 (0)