Ticket #1443: 1443_updated.diff

File 1443_updated.diff, 4.2 KB (added by Philippe Raoult, 17 years ago)

updated patch against [7322]

  • django/db/models/fields/__init__.py

     
    562562        # Casts dates into string format for entry into database.
    563563        if value is not None:
    564564            try:
    565                 value = value.strftime('%Y-%m-%d')
     565                value = "%04.d-%02.d-%02.d" % (value.year,value.month,value.day) # "%Y-%m-%d
    566566            except AttributeError:
    567567                # If value is already a string it won't have a strftime method,
    568568                # so we'll just let it pass through.
     
    574574
    575575    def flatten_data(self, follow, obj=None):
    576576        val = self._get_val_from_obj(obj)
    577         return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or '')}
     577        return {self.attname: (val is not None and ("%04.d-%02.d-%02.d" % (val.year,val.month,val.day)) or '')}
    578578
    579579    def formfield(self, **kwargs):
    580580        defaults = {'form_class': forms.DateField}
  • django/core/serializers/json.py

     
    4646    JSONEncoder subclass that knows how to encode date/time and decimal types.
    4747    """
    4848
    49     DATE_FORMAT = "%Y-%m-%d"
    50     TIME_FORMAT = "%H:%M:%S"
     49    DATE_FORMAT = "%04.d-%02.d-%02.d" # %Y-%m-%d
     50    TIME_FORMAT = "%02.d:%02.d:%02.d" # %H:%M:%S
    5151
    5252    def default(self, o):
    5353        if isinstance(o, datetime.datetime):
    54             return o.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT))
     54            fmt = "%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT)
     55            return fmt % (o.year, o.month, o.day, o.hour, o.minute, o.second)
    5556        elif isinstance(o, datetime.date):
    56             return o.strftime(self.DATE_FORMAT)
     57            return self.DATE_FORMAT % (o.year, o.month, o.day)
    5758        elif isinstance(o, datetime.time):
    58             return o.strftime(self.TIME_FORMAT)
     59            return self.TIME_FORMAT % (o.hour, o.minute, o.second)
    5960        elif isinstance(o, decimal.Decimal):
    6061            return str(o)
    6162        else:
  • django/core/serializers/base.py

     
    5959        Convert a field's value to a string.
    6060        """
    6161        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)
    6364        else:
    6465            value = field.flatten_data(follow=None, obj=obj).get(field.name, "")
    6566        return smart_unicode(value)
  • django/core/validators.py

     
    141141    # Could use time.strptime here and catch errors, but datetime.date below
    142142    # produces much friendlier error messages.
    143143    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
    148145    try:
    149146        date(year, month, day)
    150147    except ValueError, e:
  • tests/regressiontests/serializers_regress/tests.py

     
    255255
    256256    (data_obj, 800, AutoNowDateTimeData, datetime.datetime(2006,6,16,10,42,37)),
    257257    (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)),
    258261]
    259262
    260263# Because Oracle treats the empty string as NULL, Oracle is expected to fail
Back to Top