Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with tzinfo.zone check in factory.get #664

Merged
merged 2 commits into from Sep 10, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions arrow/arrow.py
Expand Up @@ -66,6 +66,7 @@ def __init__(
elif (
isinstance(tzinfo, dt_tzinfo)
and hasattr(tzinfo, "localize")
and hasattr(tzinfo, "zone")
and tzinfo.zone
):
tzinfo = parser.TzinfoParser.parse(tzinfo.zone)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
@@ -1,5 +1,6 @@
backports.functools_lru_cache==1.5.0; python_version == "2.7"
chai==1.1.2
dateparser==0.7.*
mock==3.0.*
nose==1.3.7
nose-cov==1.6
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -25,7 +25,7 @@ ignore = E203,E501,W503
line_length = 88
multi_line_output = 3
include_trailing_comma = true
known_third_party = chai,dateutil,mock,pytz,setuptools,simplejson
known_third_party = chai,dateparser,dateutil,mock,pytz,setuptools,simplejson

[bdist_wheel]
universal = 1
9 changes: 9 additions & 0 deletions tests/factory_tests.py
Expand Up @@ -2,6 +2,7 @@
import time
from datetime import date, datetime

import dateparser
from chai import Chai
from dateutil import tz

Expand Down Expand Up @@ -102,6 +103,14 @@ def test_one_arg_tzinfo(self):

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

# regression test for issue #658
def test_one_arg_dateparser_datetime(self):
expected = datetime(1990, 1, 1).replace(tzinfo=tz.tzutc())
# dateparser outputs: datetime.datetime(1990, 1, 1, 0, 0, tzinfo=<StaticTzInfo 'UTC\+00:00'>)
parsed_date = dateparser.parse("1990-01-01T00:00:00+00:00")
dt_output = self.factory.get(parsed_date)._datetime.replace(tzinfo=tz.tzutc())
self.assertEqual(dt_output, expected)

def test_kwarg_tzinfo(self):

self.expected = (
Expand Down
14 changes: 11 additions & 3 deletions tests/parser_tests.py
Expand Up @@ -224,10 +224,18 @@ def test_parse_timestamp(self):
self.parser.parse("{:f}123456".format(float_timestamp), "X"), self.expected
)

negative_timestamp = -1565358758
self.expected = datetime.fromtimestamp(negative_timestamp, tz=tz_utc)
# regression test for issue #662
negative_int_timestamp = -int_timestamp
self.expected = datetime.fromtimestamp(negative_int_timestamp, tz=tz_utc)
self.assertEqual(
self.parser.parse("{:d}".format(negative_timestamp), "X"), self.expected
self.parser.parse("{:d}".format(negative_int_timestamp), "X"), self.expected
)

negative_float_timestamp = -float_timestamp
self.expected = datetime.fromtimestamp(negative_float_timestamp, tz=tz_utc)
self.assertEqual(
self.parser.parse("{:f}".format(negative_float_timestamp), "X"),
self.expected,
)

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