summaryrefslogtreecommitdiff
path: root/date.py
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2011-04-26 09:42:54 +0200
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2011-04-26 09:42:54 +0200
commit73f15f317e1ac5c193ee34f0cbce59adbb9af5b3 (patch)
treeaa4c43e5d532637ba4bac26203117af5aad3aa2e /date.py
parentddb1cca3c986cac3af2866bb9800b39f99bb262d (diff)
downloadlogilab-common-73f15f317e1ac5c193ee34f0cbce59adbb9af5b3.tar.gz
date: shortcut to avoid recreating a datetime when not necessary
Diffstat (limited to 'date.py')
-rw-r--r--date.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/date.py b/date.py
index 0dbbf51..b069a6f 100644
--- a/date.py
+++ b/date.py
@@ -304,9 +304,13 @@ def ustrftime(somedate, fmt='%Y-%m-%d'):
return unicode(fmt) % fields
def utcdatetime(dt):
+ if dt.tzinfo is None:
+ return dt
return datetime(*dt.utctimetuple()[:7])
def utctime(dt):
+ if dt.tzinfo is None:
+ return dt
return (dt + dt.utcoffset() + dt.dst()).replace(tzinfo=None)
def datetime_to_seconds(date):