Fix folio dates a century early in the project database

diagram_info.date -- and project_summary_view.date, which the summary
table dialog queries -- held the folio date read back from the title
block's text: QLocale::system().toDate() of the string
updateDiagramContextForTitleBlock() writes in the locale's short format.
Where that format has a two-digit year (en_US "M/d/yy") Qt reads the year
back as 19xx, so 741.qet's 2010-09-21 became 1910-09-21, and so did every
dated folio of the 24 examples (109 of 109).

bindDiagramInfoValues() now binds the folio's own date,
BorderTitleBlock::date(), the value that text was made from. A folio set
to show the current date or none gives the same date as before.

tst_dbfoliodate runs --run on examples/741.qet under LC_ALL=en_US.UTF-8
and expects 2010-09-21 from project_summary_view: 1910-09-21 without this
change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-29 14:14:15 +13:00
parent fdcdfd749e
commit 3139fa54f7
3 changed files with 90 additions and 3 deletions
+6 -3
View File
@@ -1741,9 +1741,12 @@ void projectDataBase::bindDiagramInfoValues(QSqlQuery &query, Diagram *diagram)
for (auto key : QETInformation::diagramInfoKeys())
{
if (key == "date") {
query.bindValue( ":date",
QLocale::system().toDate(infos.value("date").toString(),
QLocale::ShortFormat));
//The folio's own date, not the title block's text read
//back: that text is the locale's short format, and where
//it has a two-digit year (en_US "M/d/yy") toDate() reads
//2010 back as 1910.
query.bindValue(QStringLiteral(":date"),
diagram->border_and_titleblock.date());
} else {
auto value = infos.value(key);
auto bind = key.prepend(":");
+12
View File
@@ -344,6 +344,18 @@ if(QET_HAS_SCRIPTING)
target_compile_definitions(tst_scriptconductoruuid PRIVATE
"QET_TEST_BINARY_PATH=\"$<TARGET_FILE:qelectrotech>\"")
# The project database keeps a folio's date with its century: 741.qet's
# 2010-09-21, read through project_summary_view under LC_ALL=en_US.UTF-8.
add_executable(
tst_dbfoliodate
tst_dbfoliodate.cpp)
add_test(NAME tst_dbfoliodate COMMAND tst_dbfoliodate)
add_dependencies(tst_dbfoliodate qelectrotech)
target_link_libraries(tst_dbfoliodate PRIVATE Qt::Test)
target_compile_definitions(tst_dbfoliodate PRIVATE
"QET_TEST_BINARY_PATH=\"$<TARGET_FILE:qelectrotech>\""
"QET_EXAMPLES_DIR=\"${QET_DIR}/examples\"")
# qet.elementTerminals() lists each terminal's uuid and qet.terminalIndex()
# turns element uuid + terminal uuid back into the index the conductor
# calls take, on examples/perceuse.qet (two terminals at one point).
+72
View File
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <QtTest>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QProcess>
#include <QProcessEnvironment>
#include <QTemporaryDir>
// The project database holds each folio's own date. It used to hold the
// title block's text read back through the locale's short format, which in a
// locale with a two-digit year (en_US "M/d/yy") turned 2010 into 1910 -- in
// diagram_info and in project_summary_view, which the summary table reads.
// Runs a script through the real binary's --run on examples/741.qet, whose
// folio is dated 20100921, with LC_ALL=en_US.UTF-8.
class tst_dbfoliodate : public QObject
{
Q_OBJECT
QTemporaryDir m_dir;
private slots:
void initTestCase()
{
QVERIFY(m_dir.isValid());
QVERIFY(QFile::exists(QStringLiteral(QET_TEST_BINARY_PATH)));
}
void folioDateKeepsItsCentury()
{
const QString path = m_dir.filePath(QStringLiteral("probe.js"));
const QString home = m_dir.filePath(QStringLiteral("home"));
QDir().mkpath(home);
QFile f(path);
QVERIFY(f.open(QIODevice::WriteOnly));
f.write("qet.log('PROBE ' + JSON.stringify("
"qet.query('SELECT date FROM project_summary_view')));\n");
f.close();
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert(QStringLiteral("QT_QPA_PLATFORM"), QStringLiteral("offscreen"));
env.insert(QStringLiteral("QET_ENABLE_SCRIPTING"), QStringLiteral("1"));
env.insert(QStringLiteral("HOME"), home);
env.insert(QStringLiteral("XDG_CONFIG_HOME"), home + QStringLiteral("/config"));
env.insert(QStringLiteral("XDG_DATA_HOME"), home + QStringLiteral("/data"));
env.insert(QStringLiteral("TMPDIR"), m_dir.path());
env.insert(QStringLiteral("LC_ALL"), QStringLiteral("en_US.UTF-8"));
QProcess proc;
proc.setProcessEnvironment(env);
proc.start(QStringLiteral(QET_TEST_BINARY_PATH),
{QStringLiteral("--run"), path,
QStringLiteral(QET_EXAMPLES_DIR "/741.qet")});
QVERIFY(proc.waitForFinished(120000));
const QString out = QString::fromUtf8(proc.readAllStandardOutput()
+ proc.readAllStandardError());
QJsonArray rows;
for (const QString &line : out.split(QLatin1Char('\n'))) {
const int i = line.indexOf(QStringLiteral("PROBE "));
if (i >= 0)
rows = QJsonDocument::fromJson(line.mid(i + 6).toUtf8()).array();
}
QCOMPARE(rows.size(), 1);
QCOMPARE(rows.at(0).toObject().value(QStringLiteral("date")).toString(),
QStringLiteral("2010-09-21"));
}
};
QTEST_APPLESS_MAIN(tst_dbfoliodate)
#include "tst_dbfoliodate.moc"