summaryrefslogtreecommitdiff
path: root/factory/compat.py
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-04-21 19:35:43 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-04-21 19:38:50 +0200
commita48f6482f21994a44da14dafdeff8e7e1237cec9 (patch)
treedaa9e1dc5ffdeeaf069cb2c759ce31bc7d4b4c0e /factory/compat.py
parentb6ecfdf7b8f0b05b3e78fe3aafaf26d9c00c3259 (diff)
downloadfactory-boy-a48f6482f21994a44da14dafdeff8e7e1237cec9.tar
factory-boy-a48f6482f21994a44da14dafdeff8e7e1237cec9.tar.gz
Add FuzzyDateTime/FuzzyNaiveDateTime.
Diffstat (limited to 'factory/compat.py')
-rw-r--r--factory/compat.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/factory/compat.py b/factory/compat.py
index 84f31b7..9594550 100644
--- a/factory/compat.py
+++ b/factory/compat.py
@@ -23,6 +23,7 @@
"""Compatibility tools"""
+import datetime
import sys
PY2 = (sys.version_info[0] == 2)
@@ -33,3 +34,30 @@ if PY2:
else:
def is_string(obj):
return isinstance(obj, str)
+
+try:
+ # Python >= 3.2
+ UTC = datetime.timezone.utc
+except AttributeError:
+ try:
+ # Fallback to pytz
+ from pytz import UTC
+ except ImportError:
+
+ # Ok, let's write our own.
+ class _UTC(datetime.tzinfo):
+ """The UTC tzinfo."""
+
+ def utcoffset(self, dt):
+ return datetime.timedelta(0)
+
+ def tzname(self, dt):
+ return "UTC"
+
+ def dst(self, dt):
+ return datetime.timedelta(0)
+
+ def localize(self, dt):
+ dt.astimezone(self)
+
+ UTC = _UTC()