Skip to content

Commit dafdb69

Browse files
committed
Fix bug with tzinfo.zone
1 parent 256e53f commit dafdb69

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

arrow/arrow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __init__(
6666
elif (
6767
isinstance(tzinfo, dt_tzinfo)
6868
and hasattr(tzinfo, "localize")
69+
and hasattr(tzinfo, "zone")
6970
and tzinfo.zone
7071
):
7172
tzinfo = parser.TzinfoParser.parse(tzinfo.zone)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
backports.functools_lru_cache==1.5.0; python_version == "2.7"
22
chai==1.1.2
3+
dateparser==0.7.*
34
mock==3.0.*
45
nose==1.3.7
56
nose-cov==1.6

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ignore = E203,E501,W503
2525
line_length = 88
2626
multi_line_output = 3
2727
include_trailing_comma = true
28-
known_third_party = chai,dateutil,mock,pytz,setuptools,simplejson
28+
known_third_party = chai,dateparser,dateutil,mock,pytz,setuptools,simplejson
2929

3030
[bdist_wheel]
3131
universal = 1

tests/factory_tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
from datetime import date, datetime
44

5+
import dateparser
56
from chai import Chai
67
from dateutil import tz
78

@@ -102,6 +103,14 @@ def test_one_arg_tzinfo(self):
102103

103104
assertDtEqual(self.factory.get(tz.gettz("US/Pacific")), self.expected)
104105

106+
# regression test for issue #658
107+
def test_one_arg_dateparser_datetime(self):
108+
expected = datetime(1990, 1, 1).replace(tzinfo=tz.tzutc())
109+
# dateparser outputs: datetime.datetime(1990, 1, 1, 0, 0, tzinfo=<StaticTzInfo 'UTC\+00:00'>)
110+
parsed_date = dateparser.parse("1990-01-01T00:00:00+00:00")
111+
arrow_obj = self.factory.get(parsed_date)._datetime.replace(tzinfo=tz.tzutc())
112+
self.assertEqual(arrow_obj, expected)
113+
105114
def test_kwarg_tzinfo(self):
106115

107116
self.expected = (

tests/parser_tests.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,18 @@ def test_parse_timestamp(self):
224224
self.parser.parse("{:f}123456".format(float_timestamp), "X"), self.expected
225225
)
226226

227-
negative_timestamp = -1565358758
228-
self.expected = datetime.fromtimestamp(negative_timestamp, tz=tz_utc)
227+
# regression test for issue #662
228+
negative_int_timestamp = -int_timestamp
229+
self.expected = datetime.fromtimestamp(negative_int_timestamp, tz=tz_utc)
229230
self.assertEqual(
230-
self.parser.parse("{:d}".format(negative_timestamp), "X"), self.expected
231+
self.parser.parse("{:d}".format(negative_int_timestamp), "X"), self.expected
232+
)
233+
234+
negative_float_timestamp = -float_timestamp
235+
self.expected = datetime.fromtimestamp(negative_float_timestamp, tz=tz_utc)
236+
self.assertEqual(
237+
self.parser.parse("{:f}".format(negative_float_timestamp), "X"),
238+
self.expected,
231239
)
232240

233241
# NOTE: timestamps cannot be parsed from natural language strings (by removing the ^...$) because it will

0 commit comments

Comments
 (0)