From 2cd7aab7cf0b0533aefbef3aee6621f42f3feaab Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Tue, 7 Aug 2018 12:56:43 +0200 Subject: [PATCH] Validate (fix) date vs. time specifier --- src/frontends/qt4/GuiInfo.cpp | 1 + src/insets/InsetInfo.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/frontends/qt4/GuiInfo.cpp b/src/frontends/qt4/GuiInfo.cpp index 422eac3478..78aaf89887 100644 --- a/src/frontends/qt4/GuiInfo.cpp +++ b/src/frontends/qt4/GuiInfo.cpp @@ -218,6 +218,7 @@ GuiInfo::GuiInfo(QWidget * parent) : InsetParamsWidget(parent) connect(typeCO, SIGNAL(currentIndexChanged(int)), this, SLOT(updateArguments(int))); connect(nameLE, SIGNAL(textChanged(QString)), this, SIGNAL(changed())); + connect(fixDateLE, SIGNAL(textChanged(QString)), this, SIGNAL(changed())); connect(infoLW, SIGNAL(currentTextChanged(QString)), this, SIGNAL(changed())); } diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp index fcb2ff7ceb..dac80c4a09 100644 --- a/src/insets/InsetInfo.cpp +++ b/src/insets/InsetInfo.cpp @@ -281,9 +281,10 @@ vector> InsetInfoParams::getArguments(Buffer const * buf, QDate date; if (itype == "moddate") date = QDateTime::fromTime_t(buf->fileName().lastModified()).date(); - else if (itype == "fixdate" && !dt.empty()) - date = QDate::fromString(toqstr(dt), Qt::ISODate); - else + else if (itype == "fixdate" && !dt.empty()) { + QDate const gdate = QDate::fromString(toqstr(dt), Qt::ISODate); + date = (gdate.isValid()) ? gdate : QDate::currentDate(); + } else date = QDate::currentDate(); result.push_back(make_pair("long",getDate("long", date))); result.push_back(make_pair("short", getDate("short", date))); @@ -306,9 +307,10 @@ vector> InsetInfoParams::getArguments(Buffer const * buf, QTime time; if (itype == "modtime") time = QDateTime::fromTime_t(buf->fileName().lastModified()).time(); - else if (itype == "fixtime" && !tt.empty()) - time = QTime::fromString(toqstr(tt), Qt::ISODate); - else + else if (itype == "fixtime" && !tt.empty()) { + QTime const gtime = QTime::fromString(toqstr(tt), Qt::ISODate); + time = (gtime.isValid()) ? gtime : QTime::currentTime(); + } else time = QTime::currentTime(); result.push_back(make_pair("long",getTime("long", time))); result.push_back(make_pair("short", getTime("short", time))); -- 2.39.2