Merge pull request #7728 from freqtrade/improve_timerange
Simplify timerange handling
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
# pragma pylint: disable=missing-docstring, C0103
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import arrow
|
||||
import pytest
|
||||
|
||||
@@ -8,16 +10,28 @@ from freqtrade.exceptions import OperationalException
|
||||
|
||||
def test_parse_timerange_incorrect():
|
||||
|
||||
assert TimeRange('date', None, 1274486400, 0) == TimeRange.parse_timerange('20100522-')
|
||||
assert TimeRange(None, 'date', 0, 1274486400) == TimeRange.parse_timerange('-20100522')
|
||||
timerange = TimeRange.parse_timerange('20100522-')
|
||||
assert TimeRange('date', None, 1274486400, 0) == timerange
|
||||
assert timerange.timerange_str == '20100522-'
|
||||
timerange = TimeRange.parse_timerange('-20100522')
|
||||
assert TimeRange(None, 'date', 0, 1274486400) == timerange
|
||||
assert timerange.timerange_str == '-20100522'
|
||||
timerange = TimeRange.parse_timerange('20100522-20150730')
|
||||
assert timerange == TimeRange('date', 'date', 1274486400, 1438214400)
|
||||
assert timerange.timerange_str == '20100522-20150730'
|
||||
assert timerange.start_fmt == '2010-05-22 00:00:00'
|
||||
assert timerange.stop_fmt == '2015-07-30 00:00:00'
|
||||
|
||||
# Added test for unix timestamp - BTC genesis date
|
||||
assert TimeRange('date', None, 1231006505, 0) == TimeRange.parse_timerange('1231006505-')
|
||||
assert TimeRange(None, 'date', 0, 1233360000) == TimeRange.parse_timerange('-1233360000')
|
||||
timerange = TimeRange.parse_timerange('1231006505-1233360000')
|
||||
assert TimeRange('date', 'date', 1231006505, 1233360000) == timerange
|
||||
assert isinstance(timerange.startdt, datetime)
|
||||
assert isinstance(timerange.stopdt, datetime)
|
||||
assert timerange.startdt == datetime.fromtimestamp(1231006505, tz=timezone.utc)
|
||||
assert timerange.stopdt == datetime.fromtimestamp(1233360000, tz=timezone.utc)
|
||||
assert timerange.timerange_str == '20090103-20090131'
|
||||
|
||||
timerange = TimeRange.parse_timerange('1231006505000-1233360000000')
|
||||
assert TimeRange('date', 'date', 1231006505, 1233360000) == timerange
|
||||
@@ -45,6 +59,7 @@ def test_subtract_start():
|
||||
x = TimeRange(None, 'date', 0, 1438214400)
|
||||
x.subtract_start(300)
|
||||
assert not x.startts
|
||||
assert not x.startdt
|
||||
|
||||
x = TimeRange('date', None, 1274486400, 0)
|
||||
x.subtract_start(300)
|
||||
|
Reference in New Issue
Block a user