AnnotatedTimespan

class timespantools.AnnotatedTimespan(start_offset=NegativeInfinity, stop_offset=Infinity, annotation=None)

An annotated timespan.

>>> annotated_timespan = timespantools.AnnotatedTimespan(
...    annotation=['a', 'b', 'c'],
...    start_offset=Offset(1, 4),
...    stop_offset=Offset(7, 8),
...    )
>>> print(format(annotated_timespan))
timespantools.AnnotatedTimespan(
    start_offset=durationtools.Offset(1, 4),
    stop_offset=durationtools.Offset(7, 8),
    annotation=['a', 'b', 'c'],
    )

Annotated timespans maintain their annotations duration mutation:

>>> left, right = annotated_timespan.split_at_offset(Offset(1, 2))
>>> left.annotation.append('foo')
>>> print(format(right))
timespantools.AnnotatedTimespan(
    start_offset=durationtools.Offset(1, 2),
    stop_offset=durationtools.Offset(7, 8),
    annotation=['a', 'b', 'c', 'foo'],
    )

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_mathtools { graph [label=mathtools]; "abjad.tools.mathtools.BoundedObject.BoundedObject" [color=3, group=2, label=BoundedObject, shape=box]; } subgraph cluster_timespantools { graph [label=timespantools]; "abjad.tools.timespantools.AnnotatedTimespan.AnnotatedTimespan" [color=black, fontcolor=white, group=3, label=<<B>AnnotatedTimespan</B>>, shape=box, style="filled, rounded"]; "abjad.tools.timespantools.Timespan.Timespan" [color=4, group=3, label=Timespan, shape=box]; "abjad.tools.timespantools.Timespan.Timespan" -> "abjad.tools.timespantools.AnnotatedTimespan.AnnotatedTimespan"; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.mathtools.BoundedObject.BoundedObject"; "abjad.tools.mathtools.BoundedObject.BoundedObject" -> "abjad.tools.timespantools.Timespan.Timespan"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

annotation Gets and sets annotated timespan annotation.
axis Arithmetic mean of timespan start- and stop-offsets.
contains_timespan_improperly(timespan) Is true when timespan contains timespan improperly.
curtails_timespan(timespan) Is true when timespan curtails timespan.
delays_timespan(timespan) Is true when timespan delays timespan.
divide_by_ratio(ratio) Divides timespan by ratio.
duration Duration of timespan.
get_overlap_with_timespan(timespan) Gets duration of overlap with timespan.
happens_during_timespan(timespan) Is true when timespan happens during timespan.
intersects_timespan(timespan) Is true when timespan intersects timespan.
is_closed False for all timespans.
is_congruent_to_timespan(timespan) Is true when timespan is congruent to timespan.
is_half_closed True for all timespans.
is_half_open True for all timespans.
is_left_closed True for all timespans.
is_left_open False for all timespans.
is_open False for all timespans.
is_right_closed False for all timespans.
is_right_open True for all timespans.
is_tangent_to_timespan(timespan) Is true when timespan is tangent to timespan.
is_well_formed Is true when timespan start offset preceeds timespan stop offset.
offsets Timespan offsets.
overlaps_all_of_timespan(timespan) Is true when timespan overlaps all of timespan.
overlaps_only_start_of_timespan(timespan) Is true when timespan overlaps only start of timespan.
overlaps_only_stop_of_timespan(timespan) Is true when timespan overlaps only stop of timespan.
overlaps_start_of_timespan(timespan) Is true when timespan overlaps start of timespan.
overlaps_stop_of_timespan(timespan) Is true when timespan overlaps start of timespan.
reflect([axis]) Reflects timespan about axis.
round_offsets(multiplier[, anchor, ...]) Rounds timespan offsets to multiple of multiplier.
scale(multiplier[, anchor]) Scales timespan by multiplier.
set_duration(duration) Sets timespan duration to duration.
set_offsets([start_offset, stop_offset]) Sets timespan start offset to start_offset and stop offset to stop_offset.
split_at_offset(offset) Split into two parts when offset happens during timespan:
split_at_offsets(offsets) Split into one or more parts when offsets happens during
start_offset Timespan start offset.
starts_after_offset(offset) Is true when timespan overlaps start of timespan.
starts_after_timespan_starts(timespan) Is true when timespan starts after timespan starts.
starts_after_timespan_stops(timespan) Is true when timespan starts after timespan stops.
starts_at_offset(offset) Is true when timespan starts at offset.
starts_at_or_after_offset(offset) Is true when timespan starts at or after offset.
starts_before_offset(offset) Is true when timespan starts before offset.
starts_before_or_at_offset(offset) Is true when timespan starts before or at offset.
starts_before_timespan_starts(timespan) Is true when timespan starts before timespan starts.
starts_before_timespan_stops(timespan) Is true when timespan starts before timespan stops.
starts_during_timespan(timespan) Is true when timespan starts during timespan.
starts_when_timespan_starts(timespan) Is true when timespan starts when timespan starts.
starts_when_timespan_stops(timespan) Is true when timespan starts when timespan stops.
stop_offset Timespan stop offset.
stops_after_offset(offset) Is true when timespan stops after offset.
stops_after_timespan_starts(timespan) Is true when timespan stops when timespan starts.
stops_after_timespan_stops(timespan) Is true when timespan stops when timespan stops.
stops_at_offset(offset) Is true when timespan stops at offset.
stops_at_or_after_offset(offset) Is true when timespan stops at or after offset.
stops_before_offset(offset) Is true when timespan stops before offset.
stops_before_or_at_offset(offset) Is true when timespan stops before or at offset.
stops_before_timespan_starts(timespan) Is true when timespan stops before timespan starts.
stops_before_timespan_stops(timespan) Is true when timespan stops before timespan stops.
stops_during_timespan(timespan) Is true when timespan stops during timespan.
stops_when_timespan_starts(timespan) Is true when timespan stops when timespan starts.
stops_when_timespan_stops(timespan) Is true when timespan stops when timespan stops.
stretch(multiplier[, anchor]) Stretches timespan by multiplier relative to anchor.
translate([translation]) Translates timespan by translation.
translate_offsets([...]) Translates timespan start offset by start_offset_translation and
trisects_timespan(timespan) Is true when timespan trisects timespan.
__and__(expr) Logical AND of two timespans.
__eq__(timespan) Is true when timespan is a timespan with equal offsets.
__format__([format_specification]) Formats timespan.
__ge__(expr) Is true when expr start offset is greater or equal to timespan start offset.
__gt__(expr) Is true when expr start offset is greater than timespan start offset.
__hash__() Hashes timespan.
__illustrate__([range_]) Illustrates timespan.
__le__(expr) Is true when expr start offset is less than or equal to timespan start offset.
__len__() Defined equal to 1 for all timespans.
__lt__(expr) Is true when expr start offset is less than timespan start offset.
__ne__(timespan) Is true when timespan is not a timespan with equivalent offsets.
__or__(expr) Logical OR of two timespans.
__repr__() Gets interpreter representation of Abjad object.
__sub__(expr) Subtract expr from timespan.
__xor__(expr) Logical XOR of two timespans.

Read-only properties

(Timespan).axis

Arithmetic mean of timespan start- and stop-offsets.

>>> timespantools.Timespan(0, 10).axis
Offset(5, 1)

Returns offset.

(Timespan).duration

Duration of timespan.

>>> timespantools.Timespan(0, 10).duration
Duration(10, 1)

Returns duration.

(Timespan).is_closed

False for all timespans.

>>> timespantools.Timespan(0, 10).is_closed
False

Returns true or false.

(Timespan).is_half_closed

True for all timespans.

>>> timespantools.Timespan(0, 10).is_half_closed
True

Returns true or false.

(Timespan).is_half_open

True for all timespans.

>>> timespantools.Timespan(0, 10).is_half_open
True

Returns true or false.

(Timespan).is_left_closed

True for all timespans.

>>> timespantools.Timespan(0, 10).is_left_closed
True

Returns true or false.

(Timespan).is_left_open

False for all timespans.

>>> timespantools.Timespan(0, 10).is_left_open
False

Returns true or false.

(Timespan).is_open

False for all timespans.

>>> timespantools.Timespan(0, 10).is_open
False

Returns true or false.

(Timespan).is_right_closed

False for all timespans.

>>> timespantools.Timespan(0, 10).is_right_closed
False

Returns true or false.

(Timespan).is_right_open

True for all timespans.

>>> timespantools.Timespan(0, 10).is_right_open
True

Returns true or false.

(Timespan).is_well_formed

Is true when timespan start offset preceeds timespan stop offset. Otherwise false:

>>> timespantools.Timespan(0, 10).is_well_formed
True

Returns true or false.

(Timespan).offsets

Timespan offsets.

>>> timespantools.Timespan(0, 10).offsets
(Offset(0, 1), Offset(10, 1))

Returns offset pair.

(Timespan).start_offset

Timespan start offset.

>>> timespantools.Timespan(0, 10).start_offset
Offset(0, 1)

Returns offset.

(Timespan).stop_offset

Timespan stop offset.

>>> timespantools.Timespan(0, 10).stop_offset
Offset(10, 1)

Returns offset.

Read/write properties

AnnotatedTimespan.annotation

Gets and sets annotated timespan annotation.

Gets annotation:

>>> annotated_timespan.annotation
['a', 'b', 'c', 'foo']

Sets annotation:

>>> annotated_timespan.annotation = 'baz'

Returns arbitrary object.

Methods

(Timespan).contains_timespan_improperly(timespan)

Is true when timespan contains timespan improperly. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 10)
>>> timespan_1.contains_timespan_improperly(timespan_1)
True
>>> timespan_1.contains_timespan_improperly(timespan_2)
True
>>> timespan_2.contains_timespan_improperly(timespan_1)
False
>>> timespan_2.contains_timespan_improperly(timespan_2)
True

Returns true or false.

(Timespan).curtails_timespan(timespan)

Is true when timespan curtails timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 10)
>>> timespan_1.curtails_timespan(timespan_1)
False
>>> timespan_1.curtails_timespan(timespan_2)
False
>>> timespan_2.curtails_timespan(timespan_1)
True
>>> timespan_2.curtails_timespan(timespan_2)
False

Returns true or false.

(Timespan).delays_timespan(timespan)

Is true when timespan delays timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 15)
>>> timespan_3 = timespantools.Timespan(10, 20)
>>> timespan_1.delays_timespan(timespan_2)
True
>>> timespan_2.delays_timespan(timespan_3)
True

Returns true or false.

(Timespan).divide_by_ratio(ratio)

Divides timespan by ratio.

>>> timespan = timespantools.Timespan((1, 2), (3, 2))
>>> for x in timespan.divide_by_ratio((1, 2, 1)):
...     x
Timespan(start_offset=Offset(1, 2), stop_offset=Offset(3, 4))
Timespan(start_offset=Offset(3, 4), stop_offset=Offset(5, 4))
Timespan(start_offset=Offset(5, 4), stop_offset=Offset(3, 2))

Returns tuple of newly constructed timespans.

(Timespan).get_overlap_with_timespan(timespan)

Gets duration of overlap with timespan.

>>> timespan_1 = timespantools.Timespan(0, 15)
>>> timespan_2 = timespantools.Timespan(5, 10)
>>> timespan_3 = timespantools.Timespan(6, 6)
>>> timespan_4 = timespantools.Timespan(12, 22)
>>> timespan_1.get_overlap_with_timespan(timespan_1)
Duration(15, 1)
>>> timespan_1.get_overlap_with_timespan(timespan_2)
Duration(5, 1)
>>> timespan_1.get_overlap_with_timespan(timespan_3)
Duration(0, 1)
>>> timespan_1.get_overlap_with_timespan(timespan_4)
Duration(3, 1)
>>> timespan_2.get_overlap_with_timespan(timespan_2)
Duration(5, 1)
>>> timespan_2.get_overlap_with_timespan(timespan_3)
Duration(0, 1)
>>> timespan_2.get_overlap_with_timespan(timespan_4)
Duration(0, 1)
>>> timespan_3.get_overlap_with_timespan(timespan_3)
Duration(0, 1)
>>> timespan_3.get_overlap_with_timespan(timespan_4)
Duration(0, 1)
>>> timespan_4.get_overlap_with_timespan(timespan_4)
Duration(10, 1)

Returns duration.

(Timespan).happens_during_timespan(timespan)

Is true when timespan happens during timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 10)
>>> timespan_1.happens_during_timespan(timespan_1)
True
>>> timespan_1.happens_during_timespan(timespan_2)
False
>>> timespan_2.happens_during_timespan(timespan_1)
True
>>> timespan_2.happens_during_timespan(timespan_2)
True

Returns true or false.

(Timespan).intersects_timespan(timespan)

Is true when timespan intersects timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 15)
>>> timespan_3 = timespantools.Timespan(10, 15)
>>> timespan_1.intersects_timespan(timespan_1)
True
>>> timespan_1.intersects_timespan(timespan_2)
True
>>> timespan_1.intersects_timespan(timespan_3)
False

Returns true or false.

(Timespan).is_congruent_to_timespan(timespan)

Is true when timespan is congruent to timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 15)
>>> timespan_1.is_congruent_to_timespan(timespan_1)
True
>>> timespan_1.is_congruent_to_timespan(timespan_2)
False
>>> timespan_2.is_congruent_to_timespan(timespan_1)
False
>>> timespan_2.is_congruent_to_timespan(timespan_2)
True

Returns true or false.

(Timespan).is_tangent_to_timespan(timespan)

Is true when timespan is tangent to timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(10, 20)
>>> timespan_1.is_tangent_to_timespan(timespan_1)
False
>>> timespan_1.is_tangent_to_timespan(timespan_2)
True
>>> timespan_2.is_tangent_to_timespan(timespan_1)
True
>>> timespan_2.is_tangent_to_timespan(timespan_2)
False

Returns true or false.

(Timespan).overlaps_all_of_timespan(timespan)

Is true when timespan overlaps all of timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 6)
>>> timespan_3 = timespantools.Timespan(5, 10)
>>> timespan_1.overlaps_all_of_timespan(timespan_1)
False
>>> timespan_1.overlaps_all_of_timespan(timespan_2)
True
>>> timespan_1.overlaps_all_of_timespan(timespan_3)
False

Returns true or false.

(Timespan).overlaps_only_start_of_timespan(timespan)

Is true when timespan overlaps only start of timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(-5, 5)
>>> timespan_3 = timespantools.Timespan(4, 6)
>>> timespan_4 = timespantools.Timespan(5, 15)
>>> timespan_1.overlaps_only_start_of_timespan(timespan_1)
False
>>> timespan_1.overlaps_only_start_of_timespan(timespan_2)
False
>>> timespan_1.overlaps_only_start_of_timespan(timespan_3)
False
>>> timespan_1.overlaps_only_start_of_timespan(timespan_4)
True

Returns true or false.

(Timespan).overlaps_only_stop_of_timespan(timespan)

Is true when timespan overlaps only stop of timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(-5, 5)
>>> timespan_3 = timespantools.Timespan(4, 6)
>>> timespan_4 = timespantools.Timespan(5, 15)
>>> timespan_1.overlaps_only_stop_of_timespan(timespan_1)
False
>>> timespan_1.overlaps_only_stop_of_timespan(timespan_2)
True
>>> timespan_1.overlaps_only_stop_of_timespan(timespan_3)
False
>>> timespan_1.overlaps_only_stop_of_timespan(timespan_4)
False

Returns true or false.

(Timespan).overlaps_start_of_timespan(timespan)

Is true when timespan overlaps start of timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(-5, 5)
>>> timespan_3 = timespantools.Timespan(4, 6)
>>> timespan_4 = timespantools.Timespan(5, 15)
>>> timespan_1.overlaps_start_of_timespan(timespan_1)
False
>>> timespan_1.overlaps_start_of_timespan(timespan_2)
False
>>> timespan_1.overlaps_start_of_timespan(timespan_3)
True
>>> timespan_1.overlaps_start_of_timespan(timespan_4)
True

Returns true or false.

(Timespan).overlaps_stop_of_timespan(timespan)

Is true when timespan overlaps start of timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(-5, 5)
>>> timespan_3 = timespantools.Timespan(4, 6)
>>> timespan_4 = timespantools.Timespan(5, 15)
>>> timespan_1.overlaps_stop_of_timespan(timespan_1)
False
>>> timespan_1.overlaps_stop_of_timespan(timespan_2)
True
>>> timespan_1.overlaps_stop_of_timespan(timespan_3)
True
>>> timespan_1.overlaps_stop_of_timespan(timespan_4)
False

Returns true or false.

(Timespan).reflect(axis=None)

Reflects timespan about axis.

Example 1. Reverse timespan about timespan axis:

>>> timespantools.Timespan(3, 6).reflect()
Timespan(start_offset=Offset(3, 1), stop_offset=Offset(6, 1))

Example 2. Reverse timespan about arbitrary axis:

>>> timespantools.Timespan(3, 6).reflect(axis=Offset(10))
Timespan(start_offset=Offset(14, 1), stop_offset=Offset(17, 1))

Returns new timespan.

(Timespan).round_offsets(multiplier, anchor=Left, must_be_well_formed=True)

Rounds timespan offsets to multiple of multiplier.

>>> timespan = timespantools.Timespan((1, 5), (4, 5))
>>> timespan.round_offsets(1)
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(1, 1))
>>> timespan.round_offsets(2)
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(2, 1))
>>> timespan.round_offsets(
...     2,
...     anchor=Right,
...     )
Timespan(start_offset=Offset(-2, 1), stop_offset=Offset(0, 1))
>>> timespan.round_offsets(
...     2,
...     anchor=Right,
...     must_be_well_formed=False,
...     )
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(0, 1))

Returns new timespan.

(Timespan).scale(multiplier, anchor=Left)

Scales timespan by multiplier.

>>> timespan = timespantools.Timespan(3, 6)

Example 1. Scale timespan relative to timespan start offset:

>>> timespan.scale(Multiplier(2))
Timespan(start_offset=Offset(3, 1), stop_offset=Offset(9, 1))

Example 2. Scale timespan relative to timespan stop offset:

>>> timespan.scale(Multiplier(2), anchor=Right)
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(6, 1))

Returns new timespan.

(Timespan).set_duration(duration)

Sets timespan duration to duration.

>>> timespan = timespantools.Timespan((1, 2), (3, 2))
>>> timespan.set_duration(Duration(3, 5))
Timespan(start_offset=Offset(1, 2), stop_offset=Offset(11, 10))

Returns new timespan.

(Timespan).set_offsets(start_offset=None, stop_offset=None)

Sets timespan start offset to start_offset and stop offset to stop_offset.

>>> timespan = timespantools.Timespan((1, 2), (3, 2))
>>> timespan.set_offsets(stop_offset=Offset(7, 8))
Timespan(start_offset=Offset(1, 2), stop_offset=Offset(7, 8))

Subtracts negative start_offset from existing stop offset:

>>> timespan.set_offsets(start_offset=Offset(-1, 2))
Timespan(start_offset=Offset(1, 1), stop_offset=Offset(3, 2))

Subtracts negative stop_offset from existing stop offset:

>>> timespan.set_offsets(stop_offset=Offset(-1, 2))
Timespan(start_offset=Offset(1, 2), stop_offset=Offset(1, 1))

Returns new timespan.

(Timespan).split_at_offset(offset)

Split into two parts when offset happens during timespan:

>>> timespan = timespantools.Timespan(0, 5)
>>> left, right = timespan.split_at_offset(Offset(2))
>>> left
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(2, 1))
>>> right
Timespan(start_offset=Offset(2, 1), stop_offset=Offset(5, 1))

Otherwise return a copy of timespan:

>>> timespan.split_at_offset(Offset(12))[0]
Timespan(start_offset=Offset(0, 1), stop_offset=Offset(5, 1))

Returns one or two newly constructed timespans.

(Timespan).split_at_offsets(offsets)

Split into one or more parts when offsets happens during timespan:

>>> timespan = timespantools.Timespan(0, 10)
>>> result = timespan.split_at_offsets((1, 3, 7))
>>> print(format(result))
timespantools.TimespanInventory(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(0, 1),
            stop_offset=durationtools.Offset(1, 1),
            ),
        timespantools.Timespan(
            start_offset=durationtools.Offset(1, 1),
            stop_offset=durationtools.Offset(3, 1),
            ),
        timespantools.Timespan(
            start_offset=durationtools.Offset(3, 1),
            stop_offset=durationtools.Offset(7, 1),
            ),
        timespantools.Timespan(
            start_offset=durationtools.Offset(7, 1),
            stop_offset=durationtools.Offset(10, 1),
            ),
        ]
    )

Otherwise return a timespan inventory containing a copy of timespan:

>>> result = timespan.split_at_offsets((-100,))
>>> print(format(result))
timespantools.TimespanInventory(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(0, 1),
            stop_offset=durationtools.Offset(10, 1),
            ),
        ]
    )

Returns one or more newly constructed timespans.

(Timespan).starts_after_offset(offset)

Is true when timespan overlaps start of timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_1.starts_after_offset(Offset(-5))
True
>>> timespan_1.starts_after_offset(Offset(0))
False
>>> timespan_1.starts_after_offset(Offset(5))
False

Returns true or false.

(Timespan).starts_after_timespan_starts(timespan)

Is true when timespan starts after timespan starts. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 15)
>>> timespan_1.starts_after_timespan_starts(timespan_1)
False
>>> timespan_1.starts_after_timespan_starts(timespan_2)
False
>>> timespan_2.starts_after_timespan_starts(timespan_1)
True
>>> timespan_2.starts_after_timespan_starts(timespan_2)
False

Returns true or false.

(Timespan).starts_after_timespan_stops(timespan)

Is true when timespan starts after timespan stops. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 15)
>>> timespan_3 = timespantools.Timespan(10, 20)
>>> timespan_4 = timespantools.Timespan(15, 25)
>>> timespan_1.starts_after_timespan_stops(timespan_1)
False
>>> timespan_2.starts_after_timespan_stops(timespan_1)
False
>>> timespan_3.starts_after_timespan_stops(timespan_1)
True
>>> timespan_4.starts_after_timespan_stops(timespan_1)
True

Returns true or false.

(Timespan).starts_at_offset(offset)

Is true when timespan starts at offset. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_1.starts_at_offset(Offset(-5))
False
>>> timespan_1.starts_at_offset(Offset(0))
True
>>> timespan_1.starts_at_offset(Offset(5))
False

Returns true or false.

(Timespan).starts_at_or_after_offset(offset)

Is true when timespan starts at or after offset. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_1.starts_at_or_after_offset(Offset(-5))
True
>>> timespan_1.starts_at_or_after_offset(Offset(0))
True
>>> timespan_1.starts_at_or_after_offset(Offset(5))
False

Returns true or false.

(Timespan).starts_before_offset(offset)

Is true when timespan starts before offset. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_1.starts_before_offset(Offset(-5))
False
>>> timespan_1.starts_before_offset(Offset(0))
False
>>> timespan_1.starts_before_offset(Offset(5))
True

Returns true or false.

(Timespan).starts_before_or_at_offset(offset)

Is true when timespan starts before or at offset. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_1.starts_before_or_at_offset(Offset(-5))
False
>>> timespan_1.starts_before_or_at_offset(Offset(0))
True
>>> timespan_1.starts_before_or_at_offset(Offset(5))
True

Returns true or false.

(Timespan).starts_before_timespan_starts(timespan)

Is true when timespan starts before timespan starts. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 15)
>>> timespan_1.starts_before_timespan_starts(timespan_1)
False
>>> timespan_1.starts_before_timespan_starts(timespan_2)
True
>>> timespan_2.starts_before_timespan_starts(timespan_1)
False
>>> timespan_2.starts_before_timespan_starts(timespan_2)
False

Returns true or false.

(Timespan).starts_before_timespan_stops(timespan)

Is true when timespan starts before timespan stops. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 15)
>>> timespan_1.starts_before_timespan_stops(timespan_1)
True
>>> timespan_1.starts_before_timespan_stops(timespan_2)
True
>>> timespan_2.starts_before_timespan_stops(timespan_1)
True
>>> timespan_2.starts_before_timespan_stops(timespan_2)
True

Returns true or false.

(Timespan).starts_during_timespan(timespan)

Is true when timespan starts during timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 15)
>>> timespan_1.starts_during_timespan(timespan_1)
True
>>> timespan_1.starts_during_timespan(timespan_2)
False
>>> timespan_2.starts_during_timespan(timespan_1)
True
>>> timespan_2.starts_during_timespan(timespan_2)
True

Returns true or false.

(Timespan).starts_when_timespan_starts(timespan)

Is true when timespan starts when timespan starts. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 15)
>>> timespan_1.starts_when_timespan_starts(timespan_1)
True
>>> timespan_1.starts_when_timespan_starts(timespan_2)
False
>>> timespan_2.starts_when_timespan_starts(timespan_1)
False
>>> timespan_2.starts_when_timespan_starts(timespan_2)
True

Returns true or false.

(Timespan).starts_when_timespan_stops(timespan)

Is true when timespan starts when timespan stops. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(10, 20)
>>> timespan_1.starts_when_timespan_stops(timespan_1)
False
>>> timespan_1.starts_when_timespan_stops(timespan_2)
False
>>> timespan_2.starts_when_timespan_stops(timespan_1)
True
>>> timespan_2.starts_when_timespan_stops(timespan_2)
False

Returns true or false.

(Timespan).stops_after_offset(offset)

Is true when timespan stops after offset. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_1.starts_after_offset(Offset(-5))
True
>>> timespan_1.starts_after_offset(Offset(0))
False
>>> timespan_1.starts_after_offset(Offset(5))
False

Returns true or false.

(Timespan).stops_after_timespan_starts(timespan)

Is true when timespan stops when timespan starts. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(10, 20)
>>> timespan_1.stops_after_timespan_starts(timespan_1)
True
>>> timespan_1.stops_after_timespan_starts(timespan_2)
False
>>> timespan_2.stops_after_timespan_starts(timespan_1)
True
>>> timespan_2.stops_after_timespan_starts(timespan_2)
True

Returns true or false.

(Timespan).stops_after_timespan_stops(timespan)

Is true when timespan stops when timespan stops. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(10, 20)
>>> timespan_1.stops_after_timespan_stops(timespan_1)
False
>>> timespan_1.stops_after_timespan_stops(timespan_2)
False
>>> timespan_2.stops_after_timespan_stops(timespan_1)
True
>>> timespan_2.stops_after_timespan_stops(timespan_2)
False

Returns true or false.

(Timespan).stops_at_offset(offset)

Is true when timespan stops at offset. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_1.stops_at_offset(Offset(-5))
False
>>> timespan_1.stops_at_offset(Offset(0))
False
>>> timespan_1.stops_at_offset(Offset(5))
False

Returns true or false.

(Timespan).stops_at_or_after_offset(offset)

Is true when timespan stops at or after offset. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_1.stops_at_or_after_offset(Offset(-5))
True
>>> timespan_1.stops_at_or_after_offset(Offset(0))
True
>>> timespan_1.stops_at_or_after_offset(Offset(5))
True

Returns true or false.

(Timespan).stops_before_offset(offset)

Is true when timespan stops before offset. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_1.stops_before_offset(Offset(-5))
False
>>> timespan_1.stops_before_offset(Offset(0))
False
>>> timespan_1.stops_before_offset(Offset(5))
False

Returns true or false.

(Timespan).stops_before_or_at_offset(offset)

Is true when timespan stops before or at offset. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_1.stops_before_or_at_offset(Offset(-5))
False
>>> timespan_1.stops_before_or_at_offset(Offset(0))
False
>>> timespan_1.stops_before_or_at_offset(Offset(5))
False

Returns true or false.

(Timespan).stops_before_timespan_starts(timespan)

Is true when timespan stops before timespan starts. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(10, 20)
>>> timespan_1.stops_before_timespan_starts(timespan_1)
False
>>> timespan_1.stops_before_timespan_starts(timespan_2)
False
>>> timespan_2.stops_before_timespan_starts(timespan_1)
False
>>> timespan_2.stops_before_timespan_starts(timespan_2)
False

Returns true or false.

(Timespan).stops_before_timespan_stops(timespan)

Is true when timespan stops before timespan stops. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(10, 20)
>>> timespan_1.stops_before_timespan_stops(timespan_1)
False
>>> timespan_1.stops_before_timespan_stops(timespan_2)
True
>>> timespan_2.stops_before_timespan_stops(timespan_1)
False
>>> timespan_2.stops_before_timespan_stops(timespan_2)
False

Returns true or false.

(Timespan).stops_during_timespan(timespan)

Is true when timespan stops during timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(10, 20)
>>> timespan_1.stops_during_timespan(timespan_1)
True
>>> timespan_1.stops_during_timespan(timespan_2)
False
>>> timespan_2.stops_during_timespan(timespan_1)
False
>>> timespan_2.stops_during_timespan(timespan_2)
True

Returns true or false.

(Timespan).stops_when_timespan_starts(timespan)

Is true when timespan stops when timespan starts. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(10, 20)
>>> timespan_1.stops_when_timespan_starts(timespan_1)
False
>>> timespan_1.stops_when_timespan_starts(timespan_2)
True
>>> timespan_2.stops_when_timespan_starts(timespan_1)
False
>>> timespan_2.stops_when_timespan_starts(timespan_2)
False

Returns true or false.

(Timespan).stops_when_timespan_stops(timespan)

Is true when timespan stops when timespan stops. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(10, 20)
>>> timespan_1.stops_when_timespan_stops(timespan_1)
True
>>> timespan_1.stops_when_timespan_stops(timespan_2)
False
>>> timespan_2.stops_when_timespan_stops(timespan_1)
False
>>> timespan_2.stops_when_timespan_stops(timespan_2)
True

Returns true or false.

(Timespan).stretch(multiplier, anchor=None)

Stretches timespan by multiplier relative to anchor.

Example 1. Stretch relative to timespan start offset:

>>> timespantools.Timespan(3, 10).stretch(Multiplier(2))
Timespan(start_offset=Offset(3, 1), stop_offset=Offset(17, 1))

Example 2. Stretch relative to timespan stop offset:

>>> timespantools.Timespan(3, 10).stretch(Multiplier(2), Offset(10))
Timespan(start_offset=Offset(-4, 1), stop_offset=Offset(10, 1))

Example 3. Stretch relative to offset prior to timespan:

>>> timespantools.Timespan(3, 10).stretch(Multiplier(2), Offset(0))
Timespan(start_offset=Offset(6, 1), stop_offset=Offset(20, 1))

Example 4. Stretch relative to offset after timespan:

>>> timespantools.Timespan(3, 10).stretch(Multiplier(3), Offset(12))
Timespan(start_offset=Offset(-15, 1), stop_offset=Offset(6, 1))

Example 5. Stretch relative to offset that happens during timespan:

>>> timespantools.Timespan(3, 10).stretch(Multiplier(2), Offset(4))
Timespan(start_offset=Offset(2, 1), stop_offset=Offset(16, 1))

Returns newly emitted timespan.

(Timespan).translate(translation=None)

Translates timespan by translation.

>>> timespan = timespantools.Timespan(5, 10)
>>> timespan.translate(2)
Timespan(start_offset=Offset(7, 1), stop_offset=Offset(12, 1))

Returns new timespan.

(Timespan).translate_offsets(start_offset_translation=None, stop_offset_translation=None)

Translates timespan start offset by start_offset_translation and stop offset by stop_offset_translation:

>>> timespan = timespantools.Timespan((1, 2), (3, 2))
>>> timespan.translate_offsets(
...     start_offset_translation=Duration(-1, 8))
Timespan(start_offset=Offset(3, 8), stop_offset=Offset(3, 2))

Returns new timespan.

(Timespan).trisects_timespan(timespan)

Is true when timespan trisects timespan. Otherwise false:

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 6)
>>> timespan_1.trisects_timespan(timespan_1)
False
>>> timespan_1.trisects_timespan(timespan_2)
False
>>> timespan_2.trisects_timespan(timespan_1)
True
>>> timespan_2.trisects_timespan(timespan_2)
False

Returns true or false.

Special methods

(Timespan).__and__(expr)

Logical AND of two timespans.

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 12)
>>> timespan_3 = timespantools.Timespan(-2, 2)
>>> timespan_4 = timespantools.Timespan(10, 20)
>>> timespan_1 & timespan_2
TimespanInventory([Timespan(start_offset=Offset(5, 1), stop_offset=Offset(10, 1))])
>>> timespan_1 & timespan_3
TimespanInventory([Timespan(start_offset=Offset(0, 1), stop_offset=Offset(2, 1))])
>>> timespan_1 & timespan_4
TimespanInventory([])
>>> timespan_2 & timespan_3
TimespanInventory([])
>>> timespan_2 & timespan_4
TimespanInventory([Timespan(start_offset=Offset(10, 1), stop_offset=Offset(12, 1))])
>>> timespan_3 & timespan_4
TimespanInventory([])

Returns timespan inventory.

(Timespan).__eq__(timespan)

Is true when timespan is a timespan with equal offsets.

>>> timespantools.Timespan(1, 3) == timespantools.Timespan(1, 3)
True

Otherwise false:

>>> timespantools.Timespan(1, 3) == timespantools.Timespan(2, 3)
False

Returns true or false.

(Timespan).__format__(format_specification='')

Formats timespan.

Set format_specification to ‘’ or ‘storage’.

>>> print(format(timespan_1))
timespantools.Timespan(
    start_offset=durationtools.Offset(0, 1),
    stop_offset=durationtools.Offset(10, 1),
    )

Returns string.

(Timespan).__ge__(expr)

Is true when expr start offset is greater or equal to timespan start offset.

>>> timespan_2 >= timespan_3
True

Otherwise false:

>>> timespan_1 >= timespan_2
False

Returns true or false.

(Timespan).__gt__(expr)

Is true when expr start offset is greater than timespan start offset.

>>> timespan_2 > timespan_3
True

Otherwise false:

>>> timespan_1 > timespan_2
False

Returns true or false.

(Timespan).__hash__()

Hashes timespan.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

(Timespan).__illustrate__(range_=None)

Illustrates timespan.

Returns LilyPond file.

(Timespan).__le__(expr)

Is true when expr start offset is less than or equal to timespan start offset.

>>> timespan_2 <= timespan_3
False

Otherwise false:

>>> timespan_1 <= timespan_2
True

Returns true or false.

(Timespan).__len__()

Defined equal to 1 for all timespans.

>>> len(timespan_1)
1

Returns positive integer.

(Timespan).__lt__(expr)

Is true when expr start offset is less than timespan start offset.

>>> timespan_1 < timespan_2
True

Otherwise false:

>>> timespan_2 < timespan_3
False

Returns true or false.

(Timespan).__ne__(timespan)

Is true when timespan is not a timespan with equivalent offsets.

>>> timespantools.Timespan(1, 3) != timespantools.Timespan(2, 3)
True

Otherwise false:

>>> timespantools.Timespan(1, 3) != timespantools.Timespan(2/2, (3, 1))
False

Returns true or false.

(Timespan).__or__(expr)

Logical OR of two timespans.

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 12)
>>> timespan_3 = timespantools.Timespan(-2, 2)
>>> timespan_4 = timespantools.Timespan(10, 20)
>>> new_timespan = timespan_1 | timespan_2
>>> print(format(new_timespan))
timespantools.TimespanInventory(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(0, 1),
            stop_offset=durationtools.Offset(12, 1),
            ),
        ]
    )
>>> new_timespan = timespan_1 | timespan_3
>>> print(format(new_timespan))
timespantools.TimespanInventory(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(-2, 1),
            stop_offset=durationtools.Offset(10, 1),
            ),
        ]
    )
>>> new_timespan = timespan_1 | timespan_4
>>> print(format(new_timespan))
timespantools.TimespanInventory(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(0, 1),
            stop_offset=durationtools.Offset(20, 1),
            ),
        ]
    )
>>> new_timespan = timespan_2 | timespan_3
>>> print(format(new_timespan))
timespantools.TimespanInventory(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(-2, 1),
            stop_offset=durationtools.Offset(2, 1),
            ),
        timespantools.Timespan(
            start_offset=durationtools.Offset(5, 1),
            stop_offset=durationtools.Offset(12, 1),
            ),
        ]
    )
>>> new_timespan = timespan_2 | timespan_4
>>> print(format(new_timespan))
timespantools.TimespanInventory(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(5, 1),
            stop_offset=durationtools.Offset(20, 1),
            ),
        ]
    )
>>> new_timespan = timespan_3 | timespan_4
>>> print(format(new_timespan))
timespantools.TimespanInventory(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(-2, 1),
            stop_offset=durationtools.Offset(2, 1),
            ),
        timespantools.Timespan(
            start_offset=durationtools.Offset(10, 1),
            stop_offset=durationtools.Offset(20, 1),
            ),
        ]
    )

Returns timespan inventory.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

(Timespan).__sub__(expr)

Subtract expr from timespan.

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 12)
>>> timespan_3 = timespantools.Timespan(-2, 2)
>>> timespan_4 = timespantools.Timespan(10, 20)
>>> timespan_1 - timespan_1
TimespanInventory([])
>>> timespan_1 - timespan_2
TimespanInventory([Timespan(start_offset=Offset(0, 1), stop_offset=Offset(5, 1))])
>>> timespan_1 - timespan_3
TimespanInventory([Timespan(start_offset=Offset(2, 1), stop_offset=Offset(10, 1))])
>>> timespan_1 - timespan_4
TimespanInventory([Timespan(start_offset=Offset(0, 1), stop_offset=Offset(10, 1))])
>>> timespan_2 - timespan_1
TimespanInventory([Timespan(start_offset=Offset(10, 1), stop_offset=Offset(12, 1))])
>>> timespan_2 - timespan_2
TimespanInventory([])
>>> timespan_2 - timespan_3
TimespanInventory([Timespan(start_offset=Offset(5, 1), stop_offset=Offset(12, 1))])
>>> timespan_2 - timespan_4
TimespanInventory([Timespan(start_offset=Offset(5, 1), stop_offset=Offset(10, 1))])
>>> timespan_3 - timespan_3
TimespanInventory([])
>>> timespan_3 - timespan_1
TimespanInventory([Timespan(start_offset=Offset(-2, 1), stop_offset=Offset(0, 1))])
>>> timespan_3 - timespan_2
TimespanInventory([Timespan(start_offset=Offset(-2, 1), stop_offset=Offset(2, 1))])
>>> timespan_3 - timespan_4
TimespanInventory([Timespan(start_offset=Offset(-2, 1), stop_offset=Offset(2, 1))])
>>> timespan_4 - timespan_4
TimespanInventory([])
>>> timespan_4 - timespan_1
TimespanInventory([Timespan(start_offset=Offset(10, 1), stop_offset=Offset(20, 1))])
>>> timespan_4 - timespan_2
TimespanInventory([Timespan(start_offset=Offset(12, 1), stop_offset=Offset(20, 1))])
>>> timespan_4 - timespan_3
TimespanInventory([Timespan(start_offset=Offset(10, 1), stop_offset=Offset(20, 1))])

Returns timespan inventory.

(Timespan).__xor__(expr)

Logical XOR of two timespans.

>>> timespan_1 = timespantools.Timespan(0, 10)
>>> timespan_2 = timespantools.Timespan(5, 12)
>>> timespan_3 = timespantools.Timespan(-2, 2)
>>> timespan_4 = timespantools.Timespan(10, 20)
>>> new_timespan = timespan_1 ^ timespan_2
>>> print(format(new_timespan))
timespantools.TimespanInventory(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(0, 1),
            stop_offset=durationtools.Offset(5, 1),
            ),
        timespantools.Timespan(
            start_offset=durationtools.Offset(10, 1),
            stop_offset=durationtools.Offset(12, 1),
            ),
        ]
    )
>>> new_timespan = timespan_1 ^ timespan_3
>>> print(format(new_timespan))
timespantools.TimespanInventory(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(-2, 1),
            stop_offset=durationtools.Offset(0, 1),
            ),
        timespantools.Timespan(
            start_offset=durationtools.Offset(2, 1),
            stop_offset=durationtools.Offset(10, 1),
            ),
        ]
    )
>>> new_timespan = timespan_1 ^ timespan_4
>>> print(format(new_timespan))
timespantools.TimespanInventory(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(0, 1),
            stop_offset=durationtools.Offset(10, 1),
            ),
        timespantools.Timespan(
            start_offset=durationtools.Offset(10, 1),
            stop_offset=durationtools.Offset(20, 1),
            ),
        ]
    )
>>> new_timespan = timespan_2 ^ timespan_3
>>> print(format(new_timespan))
timespantools.TimespanInventory(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(-2, 1),
            stop_offset=durationtools.Offset(2, 1),
            ),
        timespantools.Timespan(
            start_offset=durationtools.Offset(5, 1),
            stop_offset=durationtools.Offset(12, 1),
            ),
        ]
    )
>>> new_timespan = timespan_2 ^ timespan_4
>>> print(format(new_timespan))
timespantools.TimespanInventory(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(5, 1),
            stop_offset=durationtools.Offset(10, 1),
            ),
        timespantools.Timespan(
            start_offset=durationtools.Offset(12, 1),
            stop_offset=durationtools.Offset(20, 1),
            ),
        ]
    )
>>> new_timespan = timespan_3 ^ timespan_4
>>> print(format(new_timespan))
timespantools.TimespanInventory(
    [
        timespantools.Timespan(
            start_offset=durationtools.Offset(-2, 1),
            stop_offset=durationtools.Offset(2, 1),
            ),
        timespantools.Timespan(
            start_offset=durationtools.Offset(10, 1),
            stop_offset=durationtools.Offset(20, 1),
            ),
        ]
    )

Returns timespan inventory.