]> git.lyx.org Git - lyx.git/commitdiff
Validate (fix) date vs. time specifier
authorJuergen Spitzmueller <spitz@lyx.org>
Tue, 7 Aug 2018 10:56:43 +0000 (12:56 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Tue, 7 Aug 2018 10:56:43 +0000 (12:56 +0200)
src/frontends/qt4/GuiInfo.cpp
src/insets/InsetInfo.cpp

index 422eac347803175f4abe89b1bdb9cefea4bc2563..78aaf898874d77bb8fe63657ac9cdaeefb00c10c 100644 (file)
@@ -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()));
 }
 
index fcb2ff7ceb1632a57e1c1bd74de5a0a5b5edcb5a..dac80c4a09add557a750a360376ef0003303ee80 100644 (file)
@@ -281,9 +281,10 @@ vector<pair<string,docstring>> 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<pair<string,docstring>> 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)));