Skip to content

Commit f94c191

Browse files
author
Philip de Nier
authored
Merge pull request #32 from bbc/philipn-remove-phase-offset
remove PRESERVE_START/END rounding options
2 parents 6614836 + 622f84f commit f94c191

4 files changed

Lines changed: 7 additions & 30 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# mediatimestamp Changelog
22

3+
## 1.6.0
4+
- Removed the PRESERVE_START and PRESERVE_END rounding options which are used in TimeRange.normalise().
5+
36
## 1.5.2
47
- Fixed bug in taking unions with empty ranges
58

mediatimestamp/immutable.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,6 @@ class TimeRange (BaseTimeRange):
713713
ROUND_OUT = 4
714714
ROUND_START = 5
715715
ROUND_END = 6
716-
PRESERVE_START = 7
717-
PRESERVE_END = 8
718716

719717
def __init__(self, start, end, inclusivity=INCLUSIVE):
720718
"""Construct a time range starting at start and ending at end
@@ -1196,7 +1194,7 @@ def is_empty(self):
11961194
self.start == self.end and
11971195
self.inclusivity != TimeRange.INCLUSIVE)
11981196

1199-
def normalise(self, rate_num, rate_den=1, rounding=ROUND_NEAREST, phase_offset=TimeOffset()):
1197+
def normalise(self, rate_num, rate_den=1, rounding=ROUND_NEAREST):
12001198
"""Returns a normalised half-open TimeRange based on this timerange.
12011199
12021200
The returned TimeRange will always have INCLUDE_START inclusivity.
@@ -1225,10 +1223,6 @@ def normalise(self, rate_num, rate_den=1, rounding=ROUND_NEAREST, phase_offset=T
12251223
as the start
12261224
* ROUND_END -- The end rounds to the nearest normalised timestamp, the start rounds in the same direction
12271225
as the end
1228-
* PRESERVE_START -- The start is not rounded at all, the end is adjusted to match its phase offset
1229-
(and the phase_offset parameter will be ignored)
1230-
* PRESERVE_END -- The end is not rounded at all, the start is adjusted to match its phase offset
1231-
(and the phase_offset parameter will be ignored)
12321226
"""
12331227
if rounding == TimeRange.ROUND_OUT:
12341228
start_rounding = TimeRange.ROUND_DOWN
@@ -1239,9 +1233,6 @@ def normalise(self, rate_num, rate_den=1, rounding=ROUND_NEAREST, phase_offset=T
12391233
elif rounding in [TimeRange.ROUND_START, TimeRange.ROUND_END]:
12401234
start_rounding = TimeRange.ROUND_NEAREST
12411235
end_rounding = TimeRange.ROUND_NEAREST
1242-
elif rounding in [TimeRange.PRESERVE_START, TimeRange.PRESERVE_END]:
1243-
start_rounding = TimeRange.ROUND_DOWN
1244-
end_rounding = TimeRange.ROUND_DOWN
12451236
else:
12461237
start_rounding = rounding
12471238
end_rounding = rounding
@@ -1267,20 +1258,15 @@ def normalise(self, rate_num, rate_den=1, rounding=ROUND_NEAREST, phase_offset=T
12671258
else:
12681259
start = self.start.to_count(rate_num, rate_den, TimeRange.ROUND_DOWN)
12691260

1270-
if self.bounded_before() and rounding == TimeRange.PRESERVE_START:
1271-
phase_offset = self.start.to_phase_offset(rate_num, rate_den)
1272-
elif self.bounded_after() and rounding == TimeRange.PRESERVE_END:
1273-
phase_offset = self.end.to_phase_offset(rate_num, rate_den)
1274-
12751261
if start is not None and not self.includes_start():
12761262
start += 1
12771263
if end is not None and self.includes_end():
12781264
end += 1
12791265

12801266
if start is not None:
1281-
start = Timestamp.from_count(start, rate_num, rate_den) + phase_offset
1267+
start = Timestamp.from_count(start, rate_num, rate_den)
12821268
if end is not None:
1283-
end = Timestamp.from_count(end, rate_num, rate_den) + phase_offset
1269+
end = Timestamp.from_count(end, rate_num, rate_den)
12841270

12851271
return TimeRange(start,
12861272
end,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# Basic metadata
2020
name = 'mediatimestamp'
21-
version = '1.5.2'
21+
version = '1.6.0'
2222
description = 'A timestamp library for high precision nanosecond timestamps'
2323
url = 'https://github.com/bbc/rd-apmm-python-lib-mediatimestamp'
2424
author = 'James P. Weaver'

tests/test_immutable.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,18 +1510,6 @@ def test_normalise(self):
15101510
TimeRange.from_str("[0:40000000_")),
15111511
(TimeRange.from_str("_1:10000000)"), Fraction(25, 1), TimeRange.ROUND_NEAREST,
15121512
TimeRange.from_str("_1:0)")),
1513-
(TimeRange.from_str("[0:10000000_1:0)"), Fraction(25, 1), TimeRange.PRESERVE_START,
1514-
TimeRange.from_str("[0:10000000_1:10000000)")),
1515-
(TimeRange.from_str("[0:10000000_0:970000000]"), Fraction(25, 1), TimeRange.PRESERVE_START,
1516-
TimeRange.from_str("[0:10000000_1:10000000)")),
1517-
(TimeRange.from_str("(0:10000000_0:970000000]"), Fraction(25, 1), TimeRange.PRESERVE_START,
1518-
TimeRange.from_str("[0:50000000_1:10000000)")),
1519-
(TimeRange.from_str("[0:10000000_1:0)"), Fraction(25, 1), TimeRange.PRESERVE_END,
1520-
TimeRange.from_str("[0:0_1:0)")),
1521-
(TimeRange.from_str("[0:00000000_0:970000000]"), Fraction(25, 1), TimeRange.PRESERVE_END,
1522-
TimeRange.from_str("[0:10000000_1:10000000)")),
1523-
(TimeRange.from_str("(0:00000000_0:970000000]"), Fraction(25, 1), TimeRange.PRESERVE_END,
1524-
TimeRange.from_str("[0:50000000_1:10000000)")),
15251513
]
15261514

15271515
for (tr, rate, rounding, expected) in tests_tr:

0 commit comments

Comments
 (0)