Opened 10 years ago

Closed 10 years ago

Last modified 8 years ago

#228 closed enhancement (fixed)

[patch] Better handling of timezones

Reported by: rmunn@… Owned by: adrian
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:

Description

The timezone-handling in [346] is still too naive: according to http://www.cl.cam.ac.uk/~mgk25/iso-time.html, timezones can be specified in any of the following forms:

+hh
+hhmm
+hh:mm
-hh
-hhmm
-hh:mm

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/typecasts.py
===================================================================
--- django/core/db/typecasts.py (revision 346)
+++ django/core/db/typecasts.py (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 10 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

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

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