Skip to content

Commit

Permalink
Merge pull request arrow-py#221 from bottleimp/str-wi-tz
Browse files Browse the repository at this point in the history
Modify tzinfo parameter in `get` api, Adding support for tzinfo Thanks @bottleimp
  • Loading branch information
andrewelkins committed Jul 18, 2015
2 parents 0e1ba6a + 9d551e2 commit a8da156
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion arrow/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ def get(self, *args, **kwargs):

arg_count = len(args)
locale = kwargs.get('locale', 'en_us')
tz = kwargs.get('tzinfo', None)

# () -> now, @ utc.
if arg_count == 0:
if isinstance(tz, tzinfo):
return self.type.now(tz)
return self.type.utcnow()

if arg_count == 1:
Expand Down Expand Up @@ -193,7 +196,7 @@ def get(self, *args, **kwargs):
# (str, format) -> parse.
elif isstr(arg_1) and (isstr(arg_2) or isinstance(arg_2, list)):
dt = parser.DateTimeParser(locale).parse(args[0], args[1])
return self.type.fromdatetime(dt)
return self.type.fromdatetime(dt, tzinfo=tz)

else:
raise TypeError('Can\'t parse two arguments of types \'{0}\', \'{1}\''.format(
Expand Down
8 changes: 8 additions & 0 deletions tests/factory_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ def test_two_args_other(self):
with assertRaises(TypeError):
self.factory.get(object(), object())

def test_three_args_with_tzinfo(self):

timefmt = 'YYYYMMDD'
d = '20150514'

assertEqual(self.factory.get(d, timefmt, tzinfo=tz.tzlocal()),
datetime(2015, 5, 14, tzinfo=tz.tzlocal()))

def test_three_args(self):

assertEqual(self.factory.get(2013, 1, 1), datetime(2013, 1, 1, tzinfo=tz.tzutc()))
Expand Down

0 comments on commit a8da156

Please sign in to comment.