Opened 11 years ago

Closed 11 years ago

Last modified 9 years ago

#228 closed enhancement (fixed)

[patch] Better handling of timezones

Reported by: rmunn@… Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


The timezone-handling in [346] is still too naive: according to, timezones can be specified in any of the following forms:


I propose the following patch, which can deal with any of these forms. It also saves the timezone data; although we don't currently use it for anything, this patch will make a good jumping-off point in the future if we decide to use it.

Index: django/core/db/
--- django/core/db/ (revision 346)
+++ django/core/db/ (working copy)
@@ -21,8 +21,16 @@
     # "2005-07-29 09:56:00-05"
     if not s: return None
     d, t = s.split()
-    if t[-3] in ('-', '+'):
-        t = t[:-3] # Remove the time-zone information, if it exists.
+    # Extract timezone information, if it exists. Currently we just throw
+    # it away, but in the future we may make use of it.
+    if '-' in t:
+        t, tz = t.split('-', 1)
+        tz = '-' + tz
+    elif '+' in t:
+        t, tz = t.split('+', 1)
+        tz = '+' + tz
+    else:
+        tz = ''
     dates = d.split('-')
     times = t.split(':')
     seconds = times[2]

Change History (1)

comment:1 Changed 11 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

(In [347]) Fixed #228 -- Better handling of timezones. Thanks, rmunn

Note: See TracTickets for help on using tickets.
Back to Top