API Documentation
TimeSpans.TimeSpan — TypeTimeSpan(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.
TimeSpans.start — Functionstart(span)Return the inclusive lower bound of span as a Nanosecond value.
TimeSpans.stop — Functionstop(span)Return the exclusive upper bound of span as a Nanosecond value.
TimeSpans.contains — FunctionTimeSpans.contains(a, b)Return true if the timespan b lies entirely within the timespan a, return false otherwise.
TimeSpans.overlaps — Functionoverlaps(a, b)Return true if the timespan a and the timespan b overlap, return false otherwise.
TimeSpans.shortest_timespan_containing — Functionshortest_timespan_containing(spans)Return the shortest possible TimeSpan containing all timespans in spans.
spans is assumed to be an iterable of timespans.
TimeSpans.duration — Functionduration(span)Return stop(span) - start(span).
TimeSpans.translate — Functiontranslate(span, by::Period)Return TimeSpan(start(span) + by, stop(span) + by).
TimeSpans.time_from_index — Functiontime_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 nanosecondstime_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)TimeSpans.index_from_time — Functionindex_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))
101index_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