Ticket #1443: date1900.diff
File date1900.diff, 4.2 KB (added by , 17 years ago) |
---|
-
django/db/models/fields/__init__.py
544 544 # Casts dates into string format for entry into database. 545 545 if value is not None: 546 546 try: 547 value = value.strftime('%Y-%m-%d')547 value = "%04.d-%02.d-%02.d" % (value.year,value.month,value.day) # "%Y-%m-%d 548 548 except AttributeError: 549 549 # If value is already a string it won't have a strftime method, 550 550 # so we'll just let it pass through. … … 556 556 557 557 def flatten_data(self, follow, obj=None): 558 558 val = self._get_val_from_obj(obj) 559 return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or '')}559 return {self.attname: (val is not None and ("%04.d-%02.d-%02.d" % (val.year,val.month,val.day)) or '')} 560 560 561 561 def formfield(self, **kwargs): 562 562 defaults = {'form_class': forms.DateField} -
django/core/serializers/json.py
47 47 JSONEncoder subclass that knows how to encode date/time and decimal types. 48 48 """ 49 49 50 DATE_FORMAT = "% Y-%m-%d"51 TIME_FORMAT = "% H:%M:%S"50 DATE_FORMAT = "%04.d-%02.d-%02.d" # %Y-%m-%d 51 TIME_FORMAT = "%02.d:%02.d:%02.d" # %H:%M:%S 52 52 53 53 def default(self, o): 54 54 if isinstance(o, datetime.datetime): 55 return o.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT)) 55 fmt = "%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT) 56 return fmt % (o.year, o.month, o.day, o.hour, o.minute, o.second) 56 57 elif isinstance(o, datetime.date): 57 return o.strftime(self.DATE_FORMAT)58 return self.DATE_FORMAT % (o.year, o.month, o.day) 58 59 elif isinstance(o, datetime.time): 59 return o.strftime(self.TIME_FORMAT)60 return self.TIME_FORMAT % (o.hour, o.minute, o.second) 60 61 elif isinstance(o, decimal.Decimal): 61 62 return str(o) 62 63 else: -
django/core/serializers/base.py
59 59 Convert a field's value to a string. 60 60 """ 61 61 if isinstance(field, models.DateTimeField): 62 value = getattr(obj, field.name).strftime("%Y-%m-%d %H:%M:%S") 62 dt = getattr(obj, field.name) 63 value = "%04.d-%02.d-%02.d %02.d:%02.d:%02.d" % (dt.year,dt.month,dt.day,dt.hour, dt.minute, dt.second) 63 64 elif isinstance(field, models.FileField): 64 65 value = getattr(obj, "get_%s_url" % field.name, lambda: None)() 65 66 else: -
django/core/validators.py
141 141 # Could use time.strptime here and catch errors, but datetime.date below 142 142 # produces much friendlier error messages. 143 143 year, month, day = map(int, date_string.split('-')) 144 # This check is needed because strftime is used when saving the date 145 # value to the database, and strftime requires that the year be >=1900. 146 if year < 1900: 147 raise ValidationError, _('Year must be 1900 or later.') 144 148 145 try: 149 146 date(year, month, day) 150 147 except ValueError, e: -
tests/regressiontests/serializers_regress/tests.py
255 255 256 256 (data_obj, 800, AutoNowDateTimeData, datetime.datetime(2006,6,16,10,42,37)), 257 257 (data_obj, 810, ModifyingSaveData, 42), 258 259 (data_obj, 900, DateTimeData, datetime.datetime(1,1,1,0,0,0)), 260 (data_obj, 901, DateData, datetime.date(2,2,2)), 258 261 ] 259 262 260 263 # Because Oracle treats the empty string as NULL, Oracle is expected to fail