From cbbe28d85cc47505c6e7c7e4312454a722304c66 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 3 May 2024 19:05:54 +0200 Subject: [PATCH] QPdf: cleanup date formatting in the XMP metadata Instead of manual formatting, use ISO 8601, which is what XMP wants. Specifically, XMP part 1 delegates datetime formatting to Date and Time Formats, W3C submission, September 1997 http://www.w3.org/TR/NOTE-datetime with a note that the time zone designator need not be present in XMP. This work has been kindly sponsored by the QGIS project (https://qgis.org/). Change-Id: I0468ca21e1cfde47fabdd764af215a2af2efadae Reviewed-by: Edward Welbourne --- src/gui/painting/qpdf.cpp | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 06e0d6c418..0df88198a4 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #ifndef QT_NO_COMPRESS @@ -1754,26 +1755,12 @@ int QPdfEnginePrivate::writeXmpDocumentMetaData() if (xmpDocumentMetadata.isEmpty()) { const QString producer(QString::fromLatin1("Qt " QT_VERSION_STR)); - const QDateTime now = QDateTime::currentDateTime(); - const QDate date = now.date(); - const QTime time = now.time(); - const QString timeStr = - QString::asprintf("%d-%02d-%02dT%02d:%02d:%02d", - date.year(), date.month(), date.day(), - time.hour(), time.minute(), time.second()); - - const int offset = now.offsetFromUtc(); - const int hours = (offset / 60) / 60; - const int mins = (offset / 60) % 60; - QString tzStr; - if (offset < 0) - tzStr = QString::asprintf("-%02d:%02d", -hours, -mins); - else if (offset > 0) - tzStr = QString::asprintf("+%02d:%02d", hours , mins); - else - tzStr = "Z"_L1; - - const QString metaDataDate = timeStr + tzStr; +#if QT_CONFIG(timezone) + const QDateTime now = QDateTime::currentDateTime(QTimeZone::systemTimeZone()); +#else + const QDateTime now = QDateTime::currentDateTimeUtc(); +#endif + const QString metaDataDate = now.toString(Qt::ISODate); QFile metaDataFile(":/qpdf/qpdfa_metadata.xml"_L1); bool ok = metaDataFile.open(QIODevice::ReadOnly);