From 1d9d4f774e555e6fa3dea836a00407bc6dbe69d8 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Fri, 10 Jul 2015 15:28:33 +0200 Subject: [PATCH] For python 2 --- pygal/_compat.py | 3 ++- pygal/graph/time.py | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pygal/_compat.py b/pygal/_compat.py index 56fbeb1..d83ec73 100644 --- a/pygal/_compat.py +++ b/pygal/_compat.py @@ -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() diff --git a/pygal/graph/time.py b/pygal/graph/time.py index 9c1ec7c..3f25112 100644 --- a/pygal/graph/time.py +++ b/pygal/graph/time.py @@ -21,14 +21,12 @@ Various datetime line plot """ 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 @@ -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()