Ticket #10408: 10408.diff

File 10408.diff, 1.9 KB (added by tclineks, 6 years ago)
  • django/db/backends/util.py

    diff --git a/django/db/backends/util.py b/django/db/backends/util.py
    index f9c07a9..0b7f377 100644
    a b class CursorDebugWrapper(object): 
    5050###############################################
    5151
    5252def typecast_date(s):
    53     return s and datetime.date(*map(int, s.split('-'))) or None # returns None if s is null
     53    if not s:
     54        return None
     55    dates = map(int, s.split('-'))
     56    if 0 in dates:
     57        return None
     58    return s and datetime.date(*dates) or None # returns None if s is null
    5459
    5560def typecast_time(s): # does NOT store time zone information
    5661    if not s: return None
    def typecast_timestamp(s): # does NOT store time zone information 
    7782        tz = '+' + tz
    7883    else:
    7984        tz = ''
    80     dates = d.split('-')
     85    dates = map(int, d.split('-'))
    8186    times = t.split(':')
    8287    seconds = times[2]
     88    if 0 in dates:
     89        return None
    8390    if '.' in seconds: # check whether seconds have a fractional part
    8491        seconds, microseconds = seconds.split('.')
    8592    else:
  • tests/regressiontests/db_typecasts/tests.py

    diff --git a/tests/regressiontests/db_typecasts/tests.py b/tests/regressiontests/db_typecasts/tests.py
    index f4b77fe..eb653b7 100644
    a b TEST_CASES = { 
    77    'typecast_date': (
    88        ('', None),
    99        (None, None),
     10        ('0000-00-00', None),
    1011        ('2005-08-11', datetime.date(2005, 8, 11)),
    1112        ('1990-01-01', datetime.date(1990, 1, 1)),
    1213    ),
    TEST_CASES = { 
    2829    'typecast_timestamp': (
    2930        ('', None),
    3031        (None, None),
     32        ('0000-00-00 0:00:00', None),
    3133        ('2005-08-11 0:00:00', datetime.datetime(2005, 8, 11)),
    3234        ('2005-08-11 0:30:00', datetime.datetime(2005, 8, 11, 0, 30)),
    3335        ('2005-08-11 8:50:30', datetime.datetime(2005, 8, 11, 8, 50, 30)),
Back to Top