Django

Code

Ticket #228 (closed: fixed)

Opened 3 years ago

Last modified 1 year ago

[patch] Better handling of timezones

Reported by: rmunn@pobox.com Assigned to: adrian
Milestone: Component: Database layer (models, ORM)
Version: Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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]

Attachments

Change History

07/29/05 16:40:09 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #228 ([patch] Better handling of timezones)




Change Properties
Action