Skip to content

Commit

Permalink
BUG: pytz is incompatible with time.tzname[0]
Browse files Browse the repository at this point in the history
Instead, tzlocal.get_localzone() directly returns a pytz timezone.

Affected:

* mpu.io.get_modification_datetime
* mpu.io.get_access_datetime

Closes #45
  • Loading branch information
MartinThoma committed Sep 21, 2018
1 parent c60ddc4 commit 5746b5b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions mpu/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import pickle
import platform
import sys
import time

# Make it work for Python 2+3 and with Unicode
import io as io_stl
Expand Down Expand Up @@ -322,8 +321,8 @@ def get_modification_datetime(filepath):
modification_datetime : datetime.datetime
"""
import pytz
tz = pytz.timezone(time.tzname[0])
import tzlocal
tz = tzlocal.get_localzone()
mtime = datetime.fromtimestamp(os.path.getmtime(filepath))
return mtime.replace(tzinfo=tz)

Expand All @@ -340,8 +339,8 @@ def get_access_datetime(filepath):
-------
access_datetime : datetime.datetime
"""
import pytz
tz = pytz.timezone(time.tzname[0])
import tzlocal
tz = tzlocal.get_localzone()
mtime = datetime.fromtimestamp(os.path.getatime(filepath))
return mtime.replace(tzinfo=tz)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def my_test_suite():

requires_datetime = ['pytz']
requires_image = ['Pillow']
requires_io = ['pytz']
requires_io = ['pytz', 'tzlocal']
requires_aws = ['boto3']
requires_all = (['pandas', 'python-magic'] + requires_datetime +
requires_image + requires_io + requires_aws)
Expand Down

0 comments on commit 5746b5b

Please sign in to comment.