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 <edward.welbourne@qt.io>
This commit is contained in:
parent
d61060dabf
commit
cbbe28d85c
@ -20,6 +20,7 @@
|
||||
#include <qimagewriter.h>
|
||||
#include <qnumeric.h>
|
||||
#include <qtemporaryfile.h>
|
||||
#include <qtimezone.h>
|
||||
#include <quuid.h>
|
||||
|
||||
#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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user