Commit 127e81f1 authored by Karl Ove Hufthammer's avatar Karl Ove Hufthammer

Properly handle timezones and user’s preferred date format in bundles

Before: The ‘created’ and ‘updated’ times were stored as datetimes
in the author’s time zone, but *without* a time zone marker. If a
different user had a different time zone, the time displayed would
be wrong (e.g., it could be a datetime in the future). Also, the
format of the displayed time was a strange mix of locale-aware
stuff (e.g. localised month names) and non-locale aware stuff
(the order of the different components in the datetime).

Now: The times are always stored as UTC datetimes, with an explicit
datetime marker (‘Z’). (So no information about the author’s
location is leaked.) They are always shown in the user’s preferred
short datetime format (and in the user’s time zone).

The above is true for ‘created’ and ‘updated’ times stored as
actual datetimes. Older versions of Krita only stored the date,
and in the fixed ‘dd/mm/yyyy’ format. For these bundles, the date
is displayed in the user’s preferred short date (not datetime)
format.
parent 2c5720a8
...@@ -280,7 +280,7 @@ bool KisResourceBundle::save() ...@@ -280,7 +280,7 @@ bool KisResourceBundle::save()
{ {
if (filename().isEmpty()) return false; if (filename().isEmpty()) return false;
addMeta("updated", QDateTime::currentDateTime().toString(Qt::ISODate)); addMeta("updated", QDateTime::currentDateTime().toOffsetFromUtc(0).toString(Qt::ISODate));
QDir bundleDir = KoResourcePaths::saveLocation("data", "bundles"); QDir bundleDir = KoResourcePaths::saveLocation("data", "bundles");
bundleDir.cdUp(); bundleDir.cdUp();
......
...@@ -270,14 +270,14 @@ void DlgBundleManager::itemSelected(QListWidgetItem *current, QListWidgetItem *) ...@@ -270,14 +270,14 @@ void DlgBundleManager::itemSelected(QListWidgetItem *current, QListWidgetItem *)
m_ui->lblWebsite->setToolTip(bundle->getMeta("website")); m_ui->lblWebsite->setToolTip(bundle->getMeta("website"));
m_ui->lblDescription->setPlainText(bundle->getMeta("description")); m_ui->lblDescription->setPlainText(bundle->getMeta("description"));
if (QDateTime::fromString(bundle->getMeta("created"), Qt::ISODate).isValid()) { if (QDateTime::fromString(bundle->getMeta("created"), Qt::ISODate).isValid()) {
m_ui->lblCreated->setText(QDateTime::fromString(bundle->getMeta("created"), Qt::ISODate).toString()); m_ui->lblCreated->setText(QDateTime::fromString(bundle->getMeta("created"), Qt::ISODate).toLocalTime().toString(Qt::DefaultLocaleShortDate));
} else { } else {
m_ui->lblCreated->setText(QDate::fromString(bundle->getMeta("created"), "dd/MM/yyyy").toString()); m_ui->lblCreated->setText(QDate::fromString(bundle->getMeta("created"), "dd/MM/yyyy").toString(Qt::DefaultLocaleShortDate));
} }
if (QDateTime::fromString(bundle->getMeta("updated"), Qt::ISODate).isValid()) { if (QDateTime::fromString(bundle->getMeta("updated"), Qt::ISODate).isValid()) {
m_ui->lblUpdated->setText(QDateTime::fromString(bundle->getMeta("updated"), Qt::ISODate).toString()); m_ui->lblUpdated->setText(QDateTime::fromString(bundle->getMeta("updated"), Qt::ISODate).toLocalTime().toString(Qt::DefaultLocaleShortDate));
} else { } else {
m_ui->lblUpdated->setText(QDate::fromString(bundle->getMeta("updated"), "dd/MM/yyyy").toString()); m_ui->lblUpdated->setText(QDate::fromString(bundle->getMeta("updated"), "dd/MM/yyyy").toString(Qt::DefaultLocaleShortDate));
} }
m_ui->lblPreview->setPixmap(QPixmap::fromImage(bundle->image().scaled(128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation))); m_ui->lblPreview->setPixmap(QPixmap::fromImage(bundle->image().scaled(128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
m_ui->listBundleContents->clear(); m_ui->listBundleContents->clear();
......
...@@ -204,7 +204,7 @@ KisResourceBundle *ResourceManager::saveBundle(const DlgCreateBundle &dlgCreateB ...@@ -204,7 +204,7 @@ KisResourceBundle *ResourceManager::saveBundle(const DlgCreateBundle &dlgCreateB
} }
newBundle->addMeta("fileName", bundlePath); newBundle->addMeta("fileName", bundlePath);
newBundle->addMeta("created", QDateTime::currentDateTime().toString(Qt::ISODate)); newBundle->addMeta("created", QDateTime::currentDateTime().toOffsetFromUtc(0).toString(Qt::ISODate));
if (!newBundle->save()) { if (!newBundle->save()) {
QMessageBox::critical(viewManager()->mainWindow(), i18nc("@title:window", "Krita"), i18n("Could not create the new bundle.")); QMessageBox::critical(viewManager()->mainWindow(), i18nc("@title:window", "Krita"), i18n("Could not create the new bundle."));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment