Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions btrdb/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""
General utilities for btrdb bindings
"""
from datetime import timedelta

##########################################################################
## Functions
Expand Down Expand Up @@ -123,6 +124,12 @@ def decr(self):
def incr(self):
return pointwidth(self + 1)

def to_timedelta(self):
"""
Returns the timedelta of the pointwidth.
"""
return timedelta(microseconds=self.microseconds)

def __int__(self):
return self._pointwidth

Expand Down
16 changes: 16 additions & 0 deletions tests/btrdb/utils/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,19 @@ def test_incr(self):
Test incrementing a pointwidth
"""
assert pointwidth(23).incr() == 24

@pytest.mark.parametrize(
"pw, expected",
[
(54, timedelta(days=208, seconds=43198, microseconds=509482)),
(51, timedelta(days=26, seconds=5399, microseconds=813685)),
(49, timedelta(days=6, seconds=44549, microseconds=953421)),
(46, timedelta(seconds=70368, microseconds=744178)),
(43, timedelta(seconds=8796, microseconds=93022)),
(39, timedelta(seconds=549, microseconds=755814)),
(34, timedelta(seconds=17, microseconds=179869)),
(30, timedelta(seconds=1, microseconds=73742)),
],
)
def test_to_timedelta(self, pw, expected):
assert pointwidth(pw).to_timedelta() == expected