newdb: Fix timezone problem in custom column date edit widgets

Fix a regression that could cause the dates in custom date-type columns
to change in some timezones when using th edit metadata dialog to make
unrelated changes. Fixes #1217096 [After updating metadata (i.e. new cover) home made date column (YYYY) is adjusted too](https://bugs.launchpad.net/calibre/+bug/1217096)

Merge branch 'master' of https://github.com/cbhaley/calibre
This commit is contained in:
Kovid Goyal 2013-08-27 15:20:32 +05:30
commit 4343fc777b

View File

@ -12,7 +12,7 @@ from PyQt4.Qt import (QComboBox, QLabel, QSpinBox, QDoubleSpinBox, QDateTimeEdit
QSpacerItem, QIcon, QCheckBox, QWidget, QHBoxLayout, SIGNAL,
QPushButton, QMessageBox, QToolButton, Qt)
from calibre.utils.date import qt_to_dt, now
from calibre.utils.date import qt_to_dt, now, as_local_time, as_utc
from calibre.gui2.complete2 import EditWithComplete
from calibre.gui2.comments_editor import Editor as CommentsEditor
from calibre.gui2 import UNDEFINED_QDATETIME, error_dialog
@ -189,10 +189,10 @@ class DateTime(Base):
l.addStretch(2)
w = self.widgets[1]
format = cm['display'].get('date_format','')
if not format:
format = 'dd MMM yyyy hh:mm'
w.setDisplayFormat(format)
format_ = cm['display'].get('date_format','')
if not format_:
format_ = 'dd MMM yyyy hh:mm'
w.setDisplayFormat(format_)
w.setCalendarPopup(True)
w.setMinimumDateTime(UNDEFINED_QDATETIME)
w.setSpecialValueText(_('Undefined'))
@ -214,6 +214,12 @@ class DateTime(Base):
val = qt_to_dt(val)
return val
def normalize_db_val(self, val):
return as_local_time(val) if val is not None else None
def normalize_ui_val(self, val):
return as_utc(val) if val is not None else None
class Comments(Base):
def setup_ui(self, parent):
@ -823,6 +829,12 @@ class BulkDateTime(BulkBase):
val = qt_to_dt(val)
return val
def normalize_db_val(self, val):
return as_local_time(val) if val is not None else None
def normalize_ui_val(self, val):
return as_utc(val) if val is not None else None
class BulkSeries(BulkBase):
def setup_ui(self, parent):