34 const QString v =
value(params);
38 const QTimeZone tz = d->extractTimeZone(c, params, d->timeZone);
40 const QVariant _comp =
41 (d->comparison.userType() == QMetaType::QString)
42 ? d->extractOtherDateTime(c, params, d->comparison.toString(), tz, d->inputFormat)
45 if (_comp.userType() == QMetaType::QDate) {
47 const QDate odate = _comp.toDate();
48 if (Q_UNLIKELY(!odate.isValid())) {
51 "ValidatorAfter: Invalid comparison date and time for field %s at %s::%s.",
53 qPrintable(c->controllerName()),
54 qPrintable(c->actionName()));
57 const QDate date = d->extractDate(c, v, d->inputFormat);
58 if (Q_UNLIKELY(!date.isValid())) {
61 "ValidatorAfter: Can not parse input date \"%s\" for field %s at %s::%s.",
64 qPrintable(c->controllerName()),
65 qPrintable(c->actionName()));
68 if (Q_UNLIKELY(date <= odate)) {
70 "ValidatorAfter: Validation failed at %s::%s for field %s: Input "
71 "date \"%s\" is not after \"%s\".",
72 qPrintable(c->controllerName()),
73 qPrintable(c->actionName()),
75 qPrintable(date.toString()),
76 qPrintable(odate.toString()));
79 result.
value.setValue(date);
84 }
else if (_comp.userType() == QMetaType::QDateTime) {
86 const QDateTime odatetime = _comp.toDateTime();
87 if (Q_UNLIKELY(!odatetime.isValid())) {
90 "ValidatorAfter: Invalid comparison date and time for field %s at %s::%s.",
92 qPrintable(c->controllerName()),
93 qPrintable(c->actionName()));
96 const QDateTime datetime = d->extractDateTime(c, v, d->inputFormat, tz);
97 if (Q_UNLIKELY(!datetime.isValid())) {
98 qCWarning(C_VALIDATOR,
99 "ValidatorAfter: Can not parse input date and time \"%s\" for field "
103 qPrintable(c->controllerName()),
104 qPrintable(c->actionName()));
107 if (Q_UNLIKELY(datetime <= odatetime)) {
109 "ValidatorAfter: Validation failed at %s::%s for field %s: Input "
110 "date and time \"%s\" is not after \"%s\".",
111 qPrintable(c->controllerName()),
112 qPrintable(c->actionName()),
114 qPrintable(datetime.toString()),
115 qPrintable(odatetime.toString()));
118 result.
value.setValue(datetime);
123 }
else if (_comp.userType() == QMetaType::QTime) {
125 const QTime otime = _comp.toTime();
126 if (Q_UNLIKELY(!otime.isValid())) {
127 qCWarning(C_VALIDATOR,
128 "ValidatorAfter: Invalid comparison time for field %s at %s::%s.",
130 qPrintable(c->controllerName()),
131 qPrintable(c->actionName()));
134 const QTime time = d->extractTime(c, v, d->inputFormat);
135 if (Q_UNLIKELY(!time.isValid())) {
138 "ValidatorAfter: Can not parse input time \"%s\" for field %s at %s::%s.",
141 qPrintable(c->controllerName()),
142 qPrintable(c->actionName()));
145 if (Q_UNLIKELY(time <= otime)) {
147 "ValidatorAfter: Validation failed at %s::%s for field %s: Input "
148 "time \"%s\" is not after \"%s\".",
149 qPrintable(c->controllerName()),
150 qPrintable(c->actionName()),
152 qPrintable(time.toString()),
153 qPrintable(otime.toString()));
156 result.
value.setValue(time);
162 qCWarning(C_VALIDATOR)
163 <<
"ValidatorAfter: Invalid validation data for field" <<
field() <<
"at"
164 << c->controllerName() <<
"::" << c->actionName() <<
":" << d->comparison;
175 const QVariant &errorData)
const
179 const QString _label =
label(c);
180 if (_label.isEmpty()) {
182 switch (errorData.userType()) {
183 case QMetaType::QDate:
185 QStringLiteral(
"Has to be after %1.")
186 .arg(errorData.toDate().toString(c->
locale().dateFormat(QLocale::ShortFormat)));
188 case QMetaType::QDateTime:
189 error = QStringLiteral(
"Has to be after %1.")
190 .arg(errorData.toDateTime().toString(
191 c->
locale().dateTimeFormat(QLocale::ShortFormat)));
193 case QMetaType::QTime:
195 QStringLiteral(
"Has to be after %1.")
196 .arg(errorData.toTime().toString(c->
locale().timeFormat(QLocale::ShortFormat)));
205 switch (errorData.userType()) {
206 case QMetaType::QDate:
209 "The date in the “%1” field must be after %2.")
211 errorData.toDate().toString(c->
locale().dateFormat(QLocale::ShortFormat)));
213 case QMetaType::QDateTime:
214 error = c->
translate(
"Cutelyst::ValidatorAfter",
215 "The date and time in the “%1” field must be after %2.")
217 errorData.toDateTime().toString(
218 c->
locale().dateTimeFormat(QLocale::ShortFormat)));
220 case QMetaType::QTime:
223 "The time in the “%1” field must be after %2.")
225 errorData.toTime().toString(c->
locale().timeFormat(QLocale::ShortFormat)));
QLocale locale() const noexcept
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
ValidatorAfter(const QString &field, const QVariant &comparison, const QString &timeZone=QString(), const char *inputFormat=nullptr, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new after validator.