From 72cdae03b352ccd66397b25d5641c7214d36867a Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Fri, 10 Jul 2015 15:31:11 +0200 Subject: [PATCH] Better python 2/3 timezone timestamp support --- pygal/_compat.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pygal/_compat.py b/pygal/_compat.py index d83ec73..0424f73 100644 --- a/pygal/_compat.py +++ b/pygal/_compat.py @@ -66,10 +66,8 @@ def total_seconds(td): def timestamp(x): if hasattr(x, 'timestamp'): from datetime import timezone - return x.replace(tzinfo=timezone.utc).timestamp() + if x.tzinfo is None: + return x.replace(tzinfo=timezone.utc).timestamp() + return x.timestamp() else: - if hasattr(x, 'utctimetuple'): - t = x.utctimetuple() - else: - t = x.timetuple() - return time.mktime(t) + return time.mktime(x.utctimetuple())