From d1609037ab3bf0aecc708b81d11a364e8eec9de4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 22 Jul 2013 12:09:16 +0530 Subject: [PATCH] Handle number like values stored in datetime columns --- src/calibre/db/tables.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/calibre/db/tables.py b/src/calibre/db/tables.py index 9b9ff4e9e0..f71abe2a6d 100644 --- a/src/calibre/db/tables.py +++ b/src/calibre/db/tables.py @@ -29,6 +29,12 @@ def _c_convert_timestamp(val): return None try: ret = _c_speedup.parse_date(val.strip()) + except AttributeError: + # If a value like 2001 is stored in the column, apsw will return it as + # an int + if isinstance(val, (int, float)): + return datetime(int(val), 1, 1, tzinfo=tzoffset(None, 0)).astimezone(local_tz) + ret = None except: ret = None if ret is None: