From 6a84d88d0db066e820ea6283bd150e55d7d3247f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 27 Nov 2011 17:49:08 +0530 Subject: [PATCH] Fix #896832 (datetimes - errors when sorting metadata) --- src/calibre/gui2/metadata/single_download.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/metadata/single_download.py b/src/calibre/gui2/metadata/single_download.py index 70b32a78c6..1c0f3c8042 100644 --- a/src/calibre/gui2/metadata/single_download.py +++ b/src/calibre/gui2/metadata/single_download.py @@ -28,7 +28,8 @@ from calibre.ebooks.metadata.sources.identify import (identify, urls_from_identifiers) from calibre.ebooks.metadata.book.base import Metadata from calibre.gui2 import error_dialog, NONE -from calibre.utils.date import utcnow, fromordinal, format_date +from calibre.utils.date import (utcnow, fromordinal, format_date, + UNDEFINED_DATE, as_utc) from calibre.library.comments import comments_to_html from calibre import force_unicode # }}} @@ -201,7 +202,12 @@ class ResultsModel(QAbstractTableModel): # {{{ elif col == 1: key = attrgetter('title') elif col == 2: - key = attrgetter('pubdate') + def dategetter(x): + x = getattr(x, 'pubdate', None) + if x is None: + x = UNDEFINED_DATE + return as_utc(x) + key = dategetter elif col == 3: key = attrgetter('has_cached_cover_url') elif key == 4: