Skip to content

Add TimeSpans.translate implementation? #12

@ericphanson

Description

@ericphanson
function TimeSpans.translate(span::AlignedSpan, t::TimePeriod)
    n = AlignedSpans.n_samples(span.sample_rate, abs(t)) * sign(t)
    return AlignedSpan(span.sample_rate, span.first_index + n, span.last_index + n)
end

The fallback works but outputs a TimeSpan, so you may need to round again to get back. This also has the property of always preserving the number of samples contained in the span, which maybe it's possible to get wrong with pathological rounding otherwise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions