Permalink
Browse files

Initial code. Nothing is functional at this point.

git-svn-id: https://django-timezones.googlecode.com/svn/trunk@2 86ebb30f-654e-0410-bc0d-7bf82786d749
  • Loading branch information...
1 parent 4cf30cf commit 3154246e53e9b55d704939c56b96945a594a0973 @brosner committed May 30, 2008
View
10 timezones/__init__.py
@@ -0,0 +1,10 @@
+
+import pytz
+
+def localtime_for_timezone(value, timezone):
+ """
+ Given a ``datetime.datetime`` object in UTC and a timezone represented as
+ a string, return the localized time for the timezone.
+ """
+ tz = pytz.timezone(str(timezone))
+ return pytz.localize(value).astimezone(tz)
View
10 timezones/db.py
@@ -0,0 +1,10 @@
+
+from django.db import models
+
+from timezones import forms
+
+class LocalizedDateTimeField(models.CharField):
+ def formfield(self, **kwargs):
+ defaults = {"form_class": forms.LocalizedDateTimeField}
+ defaults.update(kwargs)
+ return super(LocalizedDateTime, self).formfield(**defaults)
View
5 timezones/forms.py
@@ -0,0 +1,5 @@
+
+from django import newforms as forms
+
+class LocalizedDateTimeField(forms.Field):
+ pass
View
0 timezones/models.py
No changes.
View
11 timezones/templatetags/__init__.py
@@ -0,0 +1,11 @@
+
+from django.template import Node
+from django.template import Library
+
+from timezones import localtime_for_timezone
+
+register = Library()
+
+def localtime(value, timezone):
+ return localtime_for_timezone(value, timezone)
+register.filter("localtime", localtime)
View
12 timezones/templatetags/timezone_filters.py
@@ -0,0 +1,12 @@
+
+from django.template import Node
+from django.template import Library
+
+from timezones import localtime_for_timezone
+
+register = Library()
+
+def localtime(value, timezone):
+ return localtime_for_timezone(value, timezone)
+register.filter("localtime", localtime)
+

0 comments on commit 3154246

Please sign in to comment.