From 15b9532b7956da071fee82dc706094b5ac4bb62d Mon Sep 17 00:00:00 2001 From: Victor239 <12621257+Victor239@users.noreply.github.com> Date: Sat, 21 Mar 2026 11:18:17 +0000 Subject: [PATCH] fix: Align custom updated date columns with title page metadata Write custom datetime columns for datePublished, dateUpdated, and dateCreated from the raw datetime values tracked on the book object instead of the formatted all_metadata strings. This keeps Calibre custom date columns aligned with the metadata used to generate the FanFicFare title page and avoids format-layer mismatches when the plugin updates existing books. --- calibre-plugin/fff_plugin.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/calibre-plugin/fff_plugin.py b/calibre-plugin/fff_plugin.py index 69ead2e2..06531367 100644 --- a/calibre-plugin/fff_plugin.py +++ b/calibre-plugin/fff_plugin.py @@ -2387,6 +2387,13 @@ class FanFicFarePlugin(InterfaceAction): except Exception as e: raise_exception(meta,val,label,e) + def _get_raw_custom_date_value(self, book, meta): + return { + 'datePublished': book.get('pubdate'), + 'dateUpdated': book.get('updatedate'), + 'dateCreated': book.get('timestamp'), + }.get(meta) + def update_metadata(self, db, book_id, book, mi, options): oldmi = db.get_metadata(book_id,index_is_id=True) if prefs['keeptags']: @@ -2480,7 +2487,13 @@ class FanFicFarePlugin(InterfaceAction): continue label = coldef['label'] if coldef['datatype'] in ('enumeration','comments','datetime','series'): - self.set_custom(db, book_id, meta, book['all_metadata'][meta], label, commit=False) + val = book['all_metadata'][meta] + if coldef['datatype'] == 'datetime': + val = self._get_raw_custom_date_value(book, meta) + if not val: + logger.debug("No raw datetime value for %s, skipping custom column(%s) update."%(meta,coldef['name'])) + continue + self.set_custom(db, book_id, meta, val, label, commit=False) elif coldef['datatype'] == 'text': joined_val = book['all_metadata'][meta] # 'Contains names' custom columns need & separators. @@ -2559,6 +2572,8 @@ class FanFicFarePlugin(InterfaceAction): val = sum(items) else: val = unicode(val).replace(",","") + elif coldef['datatype'] == 'datetime': + val = self._get_raw_custom_date_value(book, meta) else: val = val if coldef['datatype'] == 'bool': @@ -2569,7 +2584,7 @@ class FanFicFarePlugin(InterfaceAction): else: val = None # for tri-state 'booleans'. Yes/No/Null # logger.debug("setting 'r' or 'added':meta:%s label:%s val:%s"%(meta,label,val)) - if val != '': + if val not in ('', None): self.set_custom(db, book_id, meta, val, label=label, commit=False) if flag == 'a':