Browse Source

Better python 2/3 timezone timestamp support

pull/242/head
Florian Mounier 10 years ago
parent
commit
72cdae03b3
  1. 8
      pygal/_compat.py

8
pygal/_compat.py

@ -66,10 +66,8 @@ def total_seconds(td):
def timestamp(x): def timestamp(x):
if hasattr(x, 'timestamp'): if hasattr(x, 'timestamp'):
from datetime import timezone from datetime import timezone
if x.tzinfo is None:
return x.replace(tzinfo=timezone.utc).timestamp() return x.replace(tzinfo=timezone.utc).timestamp()
return x.timestamp()
else: else:
if hasattr(x, 'utctimetuple'): return time.mktime(x.utctimetuple())
t = x.utctimetuple()
else:
t = x.timetuple()
return time.mktime(t)

Loading…
Cancel
Save