35 const QString v =
value(params);
39 const QTimeZone tz = ValidatorBeforePrivate::extractTimeZone(c, params, d->timeZone);
41 const QVariant _comp =
42 (d->comparison.userType() == QMetaType::QString)
43 ? d->extractOtherDateTime(c, params, d->comparison.toString(), tz, d->inputFormat)
46 if (_comp.userType() == QMetaType::QDate) {
48 const QDate odate = _comp.toDate();
49 if (Q_UNLIKELY(!odate.isValid())) {
50 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison date";
53 const QDate date = d->extractDate(c, v, d->inputFormat);
54 if (Q_UNLIKELY(!date.isValid())) {
55 qCWarning(C_VALIDATOR).noquote().nospace()
56 <<
debugString(c) <<
" Can not parse input date \"" << v <<
"\"";
59 if (Q_UNLIKELY(date >= odate)) {
60 qCDebug(C_VALIDATOR).noquote()
61 <<
debugString(c) <<
"Input" << date <<
"is not before" << odate;
64 result.
value.setValue(date);
69 }
else if (_comp.userType() == QMetaType::QDateTime) {
71 const QDateTime odatetime = _comp.toDateTime();
72 if (Q_UNLIKELY(!odatetime.isValid())) {
73 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison datetime";
76 const QDateTime datetime = d->extractDateTime(c, v, d->inputFormat, tz);
77 if (Q_UNLIKELY(!datetime.isValid())) {
78 qCWarning(C_VALIDATOR).noquote().nospace()
79 <<
debugString(c) <<
" Can not parse input datetime \"" << v <<
"\"";
82 if (Q_UNLIKELY(datetime >= odatetime)) {
83 qCDebug(C_VALIDATOR).noquote() <<
debugString(c) <<
"Input" << datetime
84 <<
"is not before" << odatetime;
87 result.
value.setValue(datetime);
92 }
else if (_comp.userType() == QMetaType::QTime) {
94 const QTime otime = _comp.toTime();
95 if (Q_UNLIKELY(!otime.isValid())) {
96 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison time";
99 const QTime time = d->extractTime(c, v, d->inputFormat);
100 if (Q_UNLIKELY(!time.isValid())) {
101 qCWarning(C_VALIDATOR).noquote().nospace()
102 <<
debugString(c) <<
" Can not parse input time \"" << v <<
"\"";
105 if (Q_UNLIKELY(time >= otime)) {
106 qCDebug(C_VALIDATOR).noquote()
107 <<
debugString(c) <<
"Input" << time <<
"is not before" << otime;
110 result.
value.setValue(time);
116 qCWarning(C_VALIDATOR).noquote()
117 <<
debugString(c) <<
"Invalid comparison data:" << d->comparison;
133 const QVariant &errorData)
const
135 const QString _label =
label(c);
136 if (_label.isEmpty()) {
138 switch (errorData.userType()) {
139 case QMetaType::QDate:
142 return c->
qtTrId(
"cutelyst-valbefore-genvalerr-date")
143 .arg(c->
locale().toString(errorData.toDate(), QLocale::ShortFormat));
144 case QMetaType::QDateTime:
147 return c->
qtTrId(
"cutelyst-valbefore-genvalerr-dt")
148 .arg(c->
locale().toString(errorData.toDateTime(), QLocale::ShortFormat));
149 case QMetaType::QTime:
152 return c->
qtTrId(
"cutelyst-valbefore-genvalerr-time")
153 .arg(c->
locale().toString(errorData.toTime(), QLocale::ShortFormat));
160 switch (errorData.userType()) {
161 case QMetaType::QDate:
164 return c->
qtTrId(
"cutelyst-valbefore-genvalerr-date-label")
165 .arg(_label, c->
locale().toString(errorData.toDate(), QLocale::ShortFormat));
166 case QMetaType::QDateTime:
170 return c->
qtTrId(
"cutelyst-valbefore-genvalerr-dt-label")
171 .arg(_label, c->
locale().toString(errorData.toDateTime(), QLocale::ShortFormat));
172 case QMetaType::QTime:
175 return c->
qtTrId(
"cutelyst-valbefore-genvalerr-time-label")
176 .arg(_label, c->
locale().toString(errorData.toTime(), QLocale::ShortFormat));
201 const QString _label =
label(c);
202 if (d->inputFormat) {
203 const QString _inputFormatTranslated =
204 d->translationContext ? c->
translate(d->translationContext, d->inputFormat)
205 : c->
qtTrId(d->inputFormat);
206 if (_label.isEmpty()) {
207 return c->
qtTrId(
"cutelyst-validator-genparseerr-dt-format")
208 .arg(_inputFormatTranslated);
210 return c->
qtTrId(
"cutelyst-validator-genparseerr-dt-format-label")
211 .arg(_label, _inputFormatTranslated);
215 if (_label.isEmpty()) {
216 switch (errorData.userType()) {
217 case QMetaType::QDateTime:
218 return c->
qtTrId(
"cutelyst-validator-genparseerr-dt");
219 case QMetaType::QTime:
220 return c->
qtTrId(
"cutelyst-validator-genparseerr-time");
221 case QMetaType::QDate:
222 return c->
qtTrId(
"cutelyst-validator-genparseerr-date");
227 switch (errorData.userType()) {
228 case QMetaType::QDateTime:
229 return c->
qtTrId(
"cutelyst-vaidator-genparseerr-dt-label").arg(_label);
230 case QMetaType::QTime:
231 return c->
qtTrId(
"cutelyst-validator-genparseerr-time-label").arg(_label);
232 case QMetaType::QDate:
233 return c->
qtTrId(
"cutelyst-validator-genparseerr-date-label").arg(_label);
QLocale locale() const noexcept
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
QString qtTrId(const char *id, int n=-1) const
ValidatorBefore(const QString &field, const QVariant &comparison, const QString &timeZone={}, const char *inputFormat=nullptr, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey={})