Ticket #5714: newforms-datetime-strip.diff

File newforms-datetime-strip.diff, 1.2 KB (added by Simon Litchfield, 17 years ago)
  • django/newforms/fields.py

     
    237237            return value.date()
    238238        if isinstance(value, datetime.date):
    239239            return value
     240        if isinstance(value, basestring):
     241            value = value.strip()
    240242        for format in self.input_formats:
    241243            try:
    242244                return datetime.date(*time.strptime(value, format)[:3])
     
    264266            return None
    265267        if isinstance(value, datetime.time):
    266268            return value
     269        if isinstance(value, basestring):
     270            value = value.strip()
    267271        for format in self.input_formats:
    268272            try:
    269273                return datetime.time(*time.strptime(value, format)[3:6])
     
    300304            return value
    301305        if isinstance(value, datetime.date):
    302306            return datetime.datetime(value.year, value.month, value.day)
     307        if isinstance(value, basestring):
     308            value = value.strip()
    303309        for format in self.input_formats:
    304310            try:
    305311                return datetime.datetime(*time.strptime(value, format)[:6])
Back to Top