Display timestamp in local timezone

This commit is contained in:
Kovid Goyal 2020-07-13 11:16:32 +05:30
parent 572341e632
commit 3aeeca3cd8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -8,9 +8,9 @@ import os
from textwrap import fill from textwrap import fill
from PyQt5.Qt import ( from PyQt5.Qt import (
QApplication, QCheckBox, QComboBox, QCursor, QFont, QHBoxLayout, QIcon, QLabel, QApplication, QCheckBox, QComboBox, QCursor, QDateTime, QFont, QHBoxLayout,
QPalette, QPushButton, QSize, QSplitter, Qt, QTextBrowser, QTimer, QToolButton, QIcon, QLabel, QPalette, QPushButton, QSize, QSplitter, Qt, QTextBrowser, QTimer,
QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal QToolButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal
) )
from calibre import prepare_string_for_xml from calibre import prepare_string_for_xml
@ -18,7 +18,6 @@ from calibre.ebooks.metadata import authors_to_string, fmt_sidx
from calibre.gui2 import Application, config, gprefs from calibre.gui2 import Application, config, gprefs
from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox
from calibre.gui2.widgets2 import Dialog from calibre.gui2.widgets2 import Dialog
from calibre.utils.iso8601 import parse_iso8601
def friendly_username(user_type, user): def friendly_username(user_type, user):
@ -393,15 +392,15 @@ class DetailsPanel(QWidget):
paras = [] paras = []
if annot['type'] == 'bookmark': if annot['type'] == 'bookmark':
paras.append(annot['title']) paras.append(a(annot['title']))
elif annot['type'] == 'highlight': elif annot['type'] == 'highlight':
paras.append(annot['highlighted_text']) paras.append(a(annot['highlighted_text']))
paras.append(annot.get('notes') or '') paras.append(a(annot.get('notes') or ''))
for para in paras: for para in paras:
annot_text += '<div style="text-align:left">' + para + '</div><div>&nbsp;</div>' annot_text += '<div style="text-align:left">' + para + '</div><div>&nbsp;</div>'
date = parse_iso8601(annot['timestamp']).strftime('%Y-%m-%d %H:%M:%S') date = QDateTime.fromString(annot['timestamp'], Qt.ISODate).toLocalTime().toString(Qt.SystemLocaleShortDate)
text = ''' text = '''
<h2 style="text-align: center">{title} [{book_format}]</h2> <h2 style="text-align: center">{title} [{book_format}]</h2>
<div style="text-align: center">{authors}</div> <div style="text-align: center">{authors}</div>
@ -414,8 +413,8 @@ class DetailsPanel(QWidget):
{text} {text}
'''.format( '''.format(
title=a(title), authors=a(authors), series=a(series_text), book_format=a(book_format), title=a(title), authors=a(authors), series=a(series_text), book_format=a(book_format),
atype=a(atype), text=annot_text, dt=_('Date'), date=date, ut=_('User'), atype=a(atype), text=annot_text, dt=_('Date'), date=a(date), ut=a(_('User')),
user=friendly_username(r['user_type'], r['user']) user=a(friendly_username(r['user_type'], r['user']))
) )
self.text_browser.setHtml(text) self.text_browser.setHtml(text)