Skip to content

Commit fc8eafd

Browse files
MDP-448 to_dt should respect default_tz for ms since epoch datetimes
Add unit tests
1 parent d733eff commit fc8eafd

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

Diff for: arctic/date/_util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def to_dt(date, default_tz=None):
8989
date : `int` or `datetime.datetime`
9090
The datetime to convert
9191
92-
default_tz : tz_info
92+
default_tz : tzinfo
9393
The TimeZone to use if none is found. If not supplied, and the
9494
datetime doesn't have a timezone, then we raise ValueError
9595
@@ -98,7 +98,7 @@ def to_dt(date, default_tz=None):
9898
Non-naive datetime
9999
"""
100100
if isinstance(date, (int, long)):
101-
return ms_to_datetime(date, mktz())
101+
return ms_to_datetime(date, default_tz)
102102
elif date.tzinfo is None:
103103
if default_tz is None:
104104
raise ValueError("Must specify a TimeZone on incoming data")

Diff for: tests/unit/date/test_util.py

+26
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import datetime as dt
55
from arctic.date import datetime_to_ms, ms_to_datetime, mktz, to_pandas_closed_closed, DateRange, OPEN_OPEN, CLOSED_CLOSED
66
from arctic.date._mktz import DEFAULT_TIME_ZONE_NAME
7+
from arctic.date._util import to_dt
78

89

910
@pytest.mark.parametrize('pdt', [
@@ -60,3 +61,28 @@ def test_daterange_closedclosed_no_tz():
6061
CLOSED_CLOSED)
6162
act = to_pandas_closed_closed(date_range)
6263
assert act == expected
64+
65+
66+
def test_to_dt_0():
67+
assert to_dt(0) == dt(1970, 1, 1, 1, tzinfo=mktz())
68+
69+
70+
def test_to_dt_0_default():
71+
assert to_dt(0, mktz('UTC')) == dt(1970, 1, 1, tzinfo=mktz('UTC'))
72+
73+
74+
def test_to_dt_dt_no_tz():
75+
with pytest.raises(ValueError):
76+
assert to_dt(dt(1970, 1, 1)) == dt(1970, 1, 1, tzinfo=mktz())
77+
78+
79+
def test_to_dt_dt_no_tz_default():
80+
assert to_dt(dt(1970, 1, 1), mktz('UTC')) == dt(1970, 1, 1, tzinfo=mktz('UTC'))
81+
82+
83+
def test_to_dt_dt_tz():
84+
assert to_dt(dt(1970, 1, 1, tzinfo=mktz('UTC'))) == dt(1970, 1, 1, tzinfo=mktz('UTC'))
85+
86+
87+
def test_to_dt_dt_tz_default():
88+
assert to_dt(dt(1970, 1, 1, tzinfo=mktz('UTC')), mktz('Europe/London')) == dt(1970, 1, 1, tzinfo=mktz('UTC'))

0 commit comments

Comments
 (0)