mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
newdb: Fix undefined custom dates not displaying as blank, depending on time zone
This commit is contained in:
parent
0356894fca
commit
6cffe0d105
@ -15,7 +15,7 @@ from calibre.gui2 import UNDEFINED_QDATETIME, error_dialog, rating_font
|
|||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows
|
||||||
from calibre.gui2.widgets import EnLineEdit
|
from calibre.gui2.widgets import EnLineEdit
|
||||||
from calibre.gui2.complete2 import EditWithComplete
|
from calibre.gui2.complete2 import EditWithComplete
|
||||||
from calibre.utils.date import now, format_date, qt_to_dt
|
from calibre.utils.date import now, format_date, qt_to_dt, is_date_undefined
|
||||||
from calibre.utils.config import tweaks
|
from calibre.utils.config import tweaks
|
||||||
from calibre.utils.formatter import validation_formatter
|
from calibre.utils.formatter import validation_formatter
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
@ -91,10 +91,10 @@ class DateDelegate(QStyledItemDelegate): # {{{
|
|||||||
self.format = default_format
|
self.format = default_format
|
||||||
|
|
||||||
def displayText(self, val, locale):
|
def displayText(self, val, locale):
|
||||||
d = val.toDateTime()
|
d = qt_to_dt(val.toDateTime())
|
||||||
if d <= UNDEFINED_QDATETIME:
|
if is_date_undefined(d):
|
||||||
return ''
|
return ''
|
||||||
return format_date(qt_to_dt(d, as_utc=False), self.format)
|
return format_date(d, self.format)
|
||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
return DateTimeEdit(parent, self.format)
|
return DateTimeEdit(parent, self.format)
|
||||||
@ -110,17 +110,17 @@ class PubDateDelegate(QStyledItemDelegate): # {{{
|
|||||||
self.format = 'MMM yyyy'
|
self.format = 'MMM yyyy'
|
||||||
|
|
||||||
def displayText(self, val, locale):
|
def displayText(self, val, locale):
|
||||||
d = val.toDateTime()
|
d = qt_to_dt(val.toDateTime())
|
||||||
if d <= UNDEFINED_QDATETIME:
|
if is_date_undefined(d):
|
||||||
return ''
|
return ''
|
||||||
return format_date(qt_to_dt(d, as_utc=False), self.format)
|
return format_date(d, self.format)
|
||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
return DateTimeEdit(parent, self.format)
|
return DateTimeEdit(parent, self.format)
|
||||||
|
|
||||||
def setEditorData(self, editor, index):
|
def setEditorData(self, editor, index):
|
||||||
val = index.data(Qt.EditRole).toDate()
|
val = index.data(Qt.EditRole).toDate()
|
||||||
if val == UNDEFINED_QDATETIME.date():
|
if is_date_undefined(val):
|
||||||
val = QDate(2000, 1, 1)
|
val = QDate(2000, 1, 1)
|
||||||
editor.setDate(val)
|
editor.setDate(val)
|
||||||
|
|
||||||
@ -234,10 +234,10 @@ class CcDateDelegate(QStyledItemDelegate): # {{{
|
|||||||
self.format = format
|
self.format = format
|
||||||
|
|
||||||
def displayText(self, val, locale):
|
def displayText(self, val, locale):
|
||||||
d = val.toDateTime()
|
d = qt_to_dt(val.toDateTime())
|
||||||
if d <= UNDEFINED_QDATETIME:
|
if is_date_undefined(d):
|
||||||
return ''
|
return ''
|
||||||
return format_date(qt_to_dt(d, as_utc=False), self.format)
|
return format_date(d, self.format)
|
||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
return DateTimeEdit(parent, self.format)
|
return DateTimeEdit(parent, self.format)
|
||||||
@ -253,7 +253,7 @@ class CcDateDelegate(QStyledItemDelegate): # {{{
|
|||||||
|
|
||||||
def setModelData(self, editor, model, index):
|
def setModelData(self, editor, model, index):
|
||||||
val = editor.dateTime()
|
val = editor.dateTime()
|
||||||
if val <= UNDEFINED_QDATETIME:
|
if is_date_undefined(val):
|
||||||
val = None
|
val = None
|
||||||
model.setData(index, QVariant(val), Qt.EditRole)
|
model.setData(index, QVariant(val), Qt.EditRole)
|
||||||
|
|
||||||
|
@ -75,7 +75,12 @@ def is_date_undefined(qt_or_dt):
|
|||||||
if d is None:
|
if d is None:
|
||||||
return True
|
return True
|
||||||
if hasattr(d, 'toString'):
|
if hasattr(d, 'toString'):
|
||||||
d = datetime(d.year(), d.month(), d.day(), tzinfo=utc_tz)
|
if hasattr(d, 'date'):
|
||||||
|
d = d.date()
|
||||||
|
try:
|
||||||
|
d = datetime(d.year(), d.month(), d.day(), tzinfo=utc_tz)
|
||||||
|
except ValueError:
|
||||||
|
return True # Undefined QDate
|
||||||
return d.year < UNDEFINED_DATE.year or (
|
return d.year < UNDEFINED_DATE.year or (
|
||||||
d.year == UNDEFINED_DATE.year and
|
d.year == UNDEFINED_DATE.year and
|
||||||
d.month == UNDEFINED_DATE.month and
|
d.month == UNDEFINED_DATE.month and
|
||||||
|
Loading…
x
Reference in New Issue
Block a user