Validate (fix) date vs. time specifier

This commit is contained in:
Juergen Spitzmueller 2018-08-07 12:56:43 +02:00
parent 37279f6681
commit 2cd7aab7cf
2 changed files with 9 additions and 6 deletions

View 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()));
}

View 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)));