Ticket #2447: [3486] time zone support.diff
File [3486] time zone support.diff, 6.4 KB (added by , 18 years ago) |
---|
-
django/conf/__init__.py
7 7 """ 8 8 9 9 import os 10 import time 10 11 from django.conf import global_settings 11 12 12 13 ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE" … … 107 108 108 109 # move the time zone info into os.environ 109 110 os.environ['TZ'] = self.TIME_ZONE 111 time.tzset() 110 112 111 113 def get_all_members(self): 112 114 return dir(self) -
django/db/models/fields/__init__.py
7 7 from django.utils.functional import curry 8 8 from django.utils.text import capfirst 9 9 from django.utils.translation import gettext, gettext_lazy 10 from django.utils import tzinfo 10 11 import datetime, os, time 11 12 12 13 class NOT_PROVIDED: … … 414 415 def get_db_prep_lookup(self, lookup_type, value): 415 416 if lookup_type == 'range': 416 417 value = [str(v) for v in value] 417 elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte') and hasattr(value, 'strftime'):418 value = value.strftime('%Y-%m-%d')419 418 else: 420 419 value = str(value) 421 420 return Field.get_db_prep_lookup(self, lookup_type, value) … … 423 422 def pre_save(self, model_instance, add): 424 423 if self.auto_now or (self.auto_now_add and add): 425 424 value = datetime.datetime.now() 426 setattr(model_instance, self.attname, value) 425 tz = tzinfo.LocalTimezone(value) 426 setattr(model_instance, self.attname, value.replace(tzinfo=tz)) 427 427 return value 428 428 else: 429 429 return super(DateField, self).pre_save(model_instance, add) … … 732 732 def pre_save(self, model_instance, add): 733 733 if self.auto_now or (self.auto_now_add and add): 734 734 value = datetime.datetime.now().time() 735 setattr(model_instance, self.attname, value) 735 tz = tzinfo.LocalTimezone(value) 736 setattr(model_instance, self.attname, value.replace(tzinfo=tz)) 736 737 return value 737 738 else: 738 739 return super(TimeField, self).pre_save(model_instance, add) -
django/db/backends/util.py
1 1 import datetime 2 2 from time import time 3 from django.utils import tzinfo 3 4 4 5 class CursorDebugWrapper(object): 5 6 def __init__(self, cursor, db): … … 52 53 seconds, microseconds = seconds.split('.') 53 54 else: 54 55 microseconds = '0' 55 return datetime.time(int(hour), int(minutes), int(seconds), int(float('.'+microseconds) * 1000000) )56 return datetime.time(int(hour), int(minutes), int(seconds), int(float('.'+microseconds) * 1000000), None) 56 57 57 58 def typecast_timestamp(s): # does NOT store time zone information 58 59 # "2005-07-29 15:48:00.590358-05" … … 64 65 # it away, but in the future we may make use of it. 65 66 if '-' in t: 66 67 t, tz = t.split('-', 1) 67 tz = '-' + tz68 tz_factor = -1 68 69 elif '+' in t: 69 70 t, tz = t.split('+', 1) 70 tz = '+' + tz71 tz_factor = 1 71 72 else: 72 73 tz = '' 74 if len(tz) > 0: 75 # compute the offset from UTC in minutes 76 # the parsing is fairly naive and should be improved 77 hours, minutes = tz.split(':', 1) 78 minutes = int(minutes) + 60 * int(hours) 79 if tz_factor < 0: 80 minutes = 1440 - minutes 81 timezone = tzinfo.FixedOffset(minutes) 82 else: 83 timezone = None 84 73 85 dates = d.split('-') 74 86 times = t.split(':') 75 87 seconds = times[2] … … 78 90 else: 79 91 microseconds = '0' 80 92 return datetime.datetime(int(dates[0]), int(dates[1]), int(dates[2]), 81 int(times[0]), int(times[1]), int(seconds), int(float('.'+microseconds) * 1000000) )93 int(times[0]), int(times[1]), int(seconds), int(float('.'+microseconds) * 1000000), timezone) 82 94 83 95 def typecast_boolean(s): 84 96 if s is None: return None -
django/utils/dateformat.py
11 11 >>> 12 12 """ 13 13 14 from django.conf import settings 14 15 from django.utils.dates import MONTHS, MONTHS_AP, WEEKDAYS 15 16 from django.utils.tzinfo import LocalTimezone 16 17 from calendar import isleap, monthrange 17 18 import re, time 18 19 19 re_formatchars = re.compile(r'(?<!\\)([aAB dDfFgGhHiIjlLmMnNOPrsStTUwWyYzZ])')20 re_formatchars = re.compile(r'(?<!\\)([aABcCdDefFgGhHiIjlLmMnNOPrsStTUwWyYzZ])') 20 21 re_escaped = re.compile(r'\\(.)') 21 22 22 23 class Formatter(object): … … 48 49 def B(self): 49 50 "Swatch Internet time" 50 51 raise NotImplementedError 52 53 def C(self): 54 """ISO 8601 formatted time; e.g. '16:01:07' 55 Proprietary extension.""" 56 return self.data.isoformat() 57 58 def e(self): 59 "Timezone; e.g. 'America/Chicago'" 60 return settings.TIME_ZONE 51 61 52 62 def f(self): 53 63 """ … … 88 98 Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left off 89 99 if they're zero and the strings 'midnight' and 'noon' if appropriate. 90 100 Examples: '1 a.m.', '1:30 p.m.', 'midnight', 'noon', '12:30 p.m.' 91 Proprietary extension. 101 Proprietary extension. Conflicts with PHP 5.1.3's P format. 92 102 """ 93 103 if self.data.minute == 0 and self.data.hour == 0: 94 104 return 'midnight' … … 109 119 self.timezone = getattr(dt, 'tzinfo', None) 110 120 if hasattr(self.data, 'hour') and not self.timezone: 111 121 self.timezone = LocalTimezone(dt) 122 123 def c(self): 124 "ISO 8601 formatted date; e.g. '2000-12-21T16:01:07+02:00'" 125 return self.data.isoformat() 112 126 113 127 def d(self): 114 128 "Day of the month, 2 digits with leading zeros; i.e. '01' to '31'" … … 158 172 return MONTHS_AP[self.data.month] 159 173 160 174 def O(self): 161 "Difference to Greenwich timein hours; e.g. '+0200'"175 "Difference to UTC in hours; e.g. '+0200'" 162 176 tz = self.timezone.utcoffset(self.data) 163 177 return "%+03d%02d" % (tz.seconds // 3600, (tz.seconds // 60) % 60) 164 178