@@ -79,24 +79,26 @@ function stop_index_from_time(sample_rate, interval::Interval{Nanosecond,Closed,
79
79
# `time_from_index(sample_rate, last_index + 1)` gives us the _start_ of the next sample
80
80
# we subtract 1 ns to get the (inclusive) _end_ of the span associated to this sample
81
81
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))
84
86
@debug " Decrementing last index to fully fit within span"
85
87
last_index -= 1
86
88
end
87
89
88
90
# We should never need to decrement twice, but we will assert this
89
91
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) )
91
93
msg = """
92
94
[AlignedSpans] Unexpected error in `stop_index_from_time` with `RoundFullyContainedSampleSpans`:
93
95
94
96
- `sample_rate = $(sample_rate) `
95
97
- `interval = $(interval) `
96
98
- `mode = $(mode) `
97
99
- `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) `
100
102
101
103
Please file an issue on AlignedSpans.jl: https://github.com/beacon-biosignals/AlignedSpans.jl/issues/new
102
104
"""
0 commit comments