Skip to content

Commit

Permalink
For python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Jul 10, 2015
1 parent 49f2c5d commit 1d9d4f7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pygal/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def total_seconds(td):

def timestamp(x):
if hasattr(x, 'timestamp'):
return x.timestamp()
from datetime import timezone
return x.replace(tzinfo=timezone.utc).timestamp()
else:
if hasattr(x, 'utctimetuple'):
t = x.utctimetuple()
Expand Down
6 changes: 2 additions & 4 deletions pygal/graph/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
"""
from pygal.adapters import positive
from pygal.graph.xy import XY
from datetime import datetime, date, time, timedelta, timezone
from datetime import datetime, date, time, timedelta
from pygal._compat import timestamp, total_seconds


def datetime_to_timestamp(x):
if isinstance(x, datetime):
if x.tzinfo is None:
x = x.replace(tzinfo=timezone.utc)
return timestamp(x)
return x

Expand Down Expand Up @@ -84,7 +82,7 @@ class DateTimeLine(XY):
def _x_format(self):
"""Return the value formatter for this graph"""
def datetime_to_str(x):
dt = datetime.fromtimestamp(x, timezone.utc)
dt = datetime.utcfromtimestamp(x)
if self.x_value_formatter:
return self.x_value_formatter(dt)
return dt.isoformat()
Expand Down

0 comments on commit 1d9d4f7

Please sign in to comment.