From f31ac513d28a3d40be7d8cef5ee98dd5b55ffda1 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 27 Nov 2011 13:09:39 +0100 Subject: [PATCH] Fix (I hope) #896832 - datetimes - errors when sorting metadata --- src/calibre/ebooks/metadata/sources/identify.py | 3 ++- src/calibre/gui2/metadata/single_download.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/metadata/sources/identify.py b/src/calibre/ebooks/metadata/sources/identify.py index 4987b8cead..be12aae800 100644 --- a/src/calibre/ebooks/metadata/sources/identify.py +++ b/src/calibre/ebooks/metadata/sources/identify.py @@ -305,7 +305,8 @@ class ISBNMerge(object): ans.pubdate = r.pubdate break if getattr(ans.pubdate, 'year', None) == min_year: - min_date = datetime(min_year, ans.pubdate.month, ans.pubdate.day) + min_date = datetime(min_year, ans.pubdate.month, ans.pubdate.day, + tzinfo=utc_tz) else: min_date = datetime(min_year, 1, 2, tzinfo=utc_tz) ans.pubdate = min_date diff --git a/src/calibre/gui2/metadata/single_download.py b/src/calibre/gui2/metadata/single_download.py index 70b32a78c6..912f4d3988 100644 --- a/src/calibre/gui2/metadata/single_download.py +++ b/src/calibre/gui2/metadata/single_download.py @@ -28,7 +28,7 @@ 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 from calibre.library.comments import comments_to_html from calibre import force_unicode # }}} @@ -201,7 +201,7 @@ class ResultsModel(QAbstractTableModel): # {{{ elif col == 1: key = attrgetter('title') elif col == 2: - key = attrgetter('pubdate') + key = lambda x: x.pubdate if x.pubdate else UNDEFINED_DATE elif col == 3: key = attrgetter('has_cached_cover_url') elif key == 4: