Returns a DATE column as a date object: >>> convert_date('2007-02-26') datetime.date(2007, 2, 26) Illegal values are returned as str: >>> convert_date('2007-02-31') '2007-02-31' >>> convert_date('0000-00-00') '0000-00-00'
(obj)
| 287 | |
| 288 | |
| 289 | def convert_date(obj): |
| 290 | """Returns a DATE column as a date object: |
| 291 | |
| 292 | >>> convert_date('2007-02-26') |
| 293 | datetime.date(2007, 2, 26) |
| 294 | |
| 295 | Illegal values are returned as str: |
| 296 | |
| 297 | >>> convert_date('2007-02-31') |
| 298 | '2007-02-31' |
| 299 | >>> convert_date('0000-00-00') |
| 300 | '0000-00-00' |
| 301 | """ |
| 302 | if isinstance(obj, (bytes, bytearray)): |
| 303 | obj = obj.decode("ascii") |
| 304 | try: |
| 305 | return datetime.date(*[int(x) for x in obj.split("-", 2)]) |
| 306 | except ValueError: |
| 307 | return obj |
| 308 | |
| 309 | |
| 310 | def through(x): |