Commit 300752bd authored by Justin Bronn's avatar Justin Bronn
Browse files

Return None for null date/time fields in OGR-supported data sources. Thanks...

Return None for null date/time fields in OGR-supported data sources.  Thanks to Ariel Mauricio Nunez Gomez for bug report and initial patch.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@9711 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent bde7e79f
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -127,34 +127,34 @@ class OFTDate(Field):
    @property
    def value(self):
        "Returns a Python `date` object for the OFTDate field."
        yy, mm, dd, hh, mn, ss, tz = self.as_datetime()
        try:
            yy, mm, dd, hh, mn, ss, tz = self.as_datetime()
            return date(yy.value, mm.value, dd.value)
        except ValueError:
        except (ValueError, OGRException):
            return None

class OFTDateTime(Field):
    @property
    def value(self):
        "Returns a Python `datetime` object for this OFTDateTime field."
        yy, mm, dd, hh, mn, ss, tz = self.as_datetime()
        # TODO: Adapt timezone information.
        #  See http://lists.maptools.org/pipermail/gdal-dev/2006-February/007990.html
        #  The `tz` variable has values of: 0=unknown, 1=localtime (ambiguous), 
        #  100=GMT, 104=GMT+1, 80=GMT-5, etc.
        try:
            yy, mm, dd, hh, mn, ss, tz = self.as_datetime()
            return datetime(yy.value, mm.value, dd.value, hh.value, mn.value, ss.value)
        except ValueError:
        except (ValueError, OGRException):
            return None

class OFTTime(Field):
    @property
    def value(self):
        "Returns a Python `time` object for this OFTTime field."
        yy, mm, dd, hh, mn, ss, tz = self.as_datetime()
        try:
            yy, mm, dd, hh, mn, ss, tz = self.as_datetime()
            return time(hh.value, mn.value, ss.value)
        except ValueError:
        except (ValueError, OGRException):
            return None

# List fields are also just subclasses