API Documentation

TimeSpans.TimeSpanType
TimeSpan(start, stop)

Return TimeSpan(Nanosecond(start), Nanosecond(stop)) representing the interval [start, stop).

If start == stop, a single Nanosecond is added to stop since stop is an exclusive upper bound and TimeSpan operations only generally support up to nanosecond precision anyway.

The benefit of this type over e.g. Nanosecond(start):Nanosecond(1):Nanosecond(stop) is that instances of this type are guaranteed to obey TimeSpans.start(x) < TimeSpans.stop(x) by construction.

source
TimeSpans.startFunction
start(span)

Return the inclusive lower bound of span as a Nanosecond value.

source
TimeSpans.stopFunction
stop(span)

Return the exclusive upper bound of span as a Nanosecond value.

source
TimeSpans.containsFunction
TimeSpans.contains(a, b)

Return true if the timespan b lies entirely within the timespan a, return false otherwise.

source
TimeSpans.overlapsFunction
overlaps(a, b)

Return true if the timespan a and the timespan b overlap, return false otherwise.

source
TimeSpans.time_from_indexFunction
time_from_index(sample_rate, sample_index)

Given sample_rate in Hz and assuming sample_index > 0, return the earliest Nanosecond containing sample_index.

Examples:

julia> time_from_index(1, 1)
0 nanoseconds

julia> time_from_index(1, 2)
1000000000 nanoseconds

julia> time_from_index(100, 100)
990000000 nanoseconds

julia> time_from_index(100, 101)
1000000000 nanoseconds
source
time_from_index(sample_rate, sample_range::AbstractUnitRange)

Return the TimeSpan corresponding to sample_range given sample_rate in Hz:

julia> time_from_index(100, 1:100)
TimeSpan(0 nanoseconds, 1000000000 nanoseconds)

julia> time_from_index(100, 101:101)
TimeSpan(1000000000 nanoseconds, 1000000001 nanoseconds)

julia> time_from_index(100, 301:600)
TimeSpan(3000000000 nanoseconds, 6000000000 nanoseconds)
source
TimeSpans.index_from_timeFunction
index_from_time(sample_rate, sample_time::Period)

Given sample_rate in Hz, return the integer index of the most recent sample taken at sample_time. Note that sample_time must be non-negative and support convert(Nanosecond, sample_time).

Examples:

julia> index_from_time(1, Second(0))
1

julia> index_from_time(1, Second(1))
2

julia> index_from_time(100, Millisecond(999))
100

julia> index_from_time(100, Millisecond(1000))
101
source
index_from_time(sample_rate, span)

Return the UnitRange of indices corresponding to span given sample_rate in Hz:

julia> index_from_time(100, TimeSpan(Second(0), Second(1)))
1:100

julia> index_from_time(100, TimeSpan(Second(1)))
101:101

julia> index_from_time(100, TimeSpan(Second(3), Second(6)))
301:600
source