19 #include "validatorbefore_p.h"
21 #include <QtCore/QLoggingCategory>
25 Q_LOGGING_CATEGORY(C_VALIDATORBEFORE,
"cutelyst.utils.validator.before", QtWarningMsg)
28 ValidatorRule(*new ValidatorBeforePrivate(field, comparison, timeZone, inputFormat, messages, defValKey))
46 const QTimeZone tz = d->extractTimeZone(c, params, d->timeZone);
49 ? d->extractOtherDateTime(c, params, d->comparison.toString(), tz, d->inputFormat)
55 if (Q_UNLIKELY(!odate.
isValid())) {
56 qCWarning(C_VALIDATOR,
"ValidatorBefore: Invalid comparison date and time for field %s at %s::%s.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
59 const QDate date = d->extractDate(c, v, d->inputFormat);
60 if (Q_UNLIKELY(!date.
isValid())) {
61 qCWarning(C_VALIDATOR,
"ValidatorBefore: Can not parse input date \"%s\" for field %s at %s::%s.", qPrintable(v), qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
64 if (Q_UNLIKELY(date >= odate)) {
65 qCDebug(C_VALIDATOR,
"ValidatorBefore: Validation failed at %s::%s for field %s: Input date \"%s\" is not before \"%s\".", qPrintable(c->controllerName()), qPrintable(c->actionName()), qPrintable(
field()), qPrintable(date.
toString()), qPrintable(odate.
toString()));
76 if (Q_UNLIKELY(!odatetime.
isValid())) {
77 qCWarning(C_VALIDATOR,
"ValidatorBefore: Invalid comparison date and time for field %s at %s::%s.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
80 const QDateTime datetime = d->extractDateTime(c, v, d->inputFormat, tz);
81 if (Q_UNLIKELY(!datetime.
isValid())) {
82 qCWarning(C_VALIDATOR,
"ValidatorBefore: Can not parse input date and time \"%s\" for field %s at %s::%s.", qPrintable(v), qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
85 if (Q_UNLIKELY(datetime >= odatetime)) {
86 qCDebug(C_VALIDATOR,
"ValidatorBefore: Validation failed at %s::%s for field %s: Input date and time \"%s\" is not before \"%s\".", qPrintable(c->controllerName()), qPrintable(c->actionName()), qPrintable(
field()), qPrintable(datetime.
toString()), qPrintable(odatetime.
toString()));
97 if (Q_UNLIKELY(!otime.
isValid())) {
98 qCWarning(C_VALIDATOR,
"ValidatorBefore: Invalid comparison time for field %s at %s::%s.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
101 const QTime time = d->extractTime(c, v, d->inputFormat);
102 if (Q_UNLIKELY(!time.
isValid())) {
103 qCWarning(C_VALIDATOR,
"ValidatorBefore: Can not parse input time \"%s\" for field %s at %s::%s.", qPrintable(v), qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
106 if (Q_UNLIKELY(time >= otime)) {
107 qCDebug(C_VALIDATOR,
"ValidatorBefore: Validation failed at %s::%s for field %s: Input time \"%s\" is not before \"%s\".", qPrintable(c->controllerName()), qPrintable(c->actionName()), qPrintable(
field()), qPrintable(time.
toString()), qPrintable(otime.
toString()));
116 qCWarning(C_VALIDATOR) <<
"ValidatorBefore: Invalid validation data for field" <<
field() <<
"at" << c->controllerName() <<
"::" << c->actionName() <<
":" << d->comparison;
133 switch (errorData.
type()) {
150 switch(errorData.
type()) {
175 error = c->
translate(
"Cutelyst::ValidatorBefore",
"The comparison value is not a valid date and/or time, or cannot be found.");
187 if (d->inputFormat) {
190 error = c->
translate(
"Cutelyst::ValidatorBefore",
"Could not be parsed according to the follwing date and/or time format: %1").
arg(c->
translate(d->translationContext.data(), d->inputFormat));
193 error = c->
translate(
"Cutelyst::ValidatorBefore",
"The value of the “%1” field could not be parsed according to the follwing date and/or time format: %2").
arg(_label, c->
translate(d->translationContext.data(), d->inputFormat));
198 switch (errorData.
type()) {
200 error = c->
translate(
"Cutelyst::ValidatorBefore",
"Could not be parsed as date and time.");
203 error = c->
translate(
"Cutelyst::ValidatorBefore",
"Could not be parsed as time.");
206 error = c->
translate(
"Cutelyst::ValidatorBefore",
"Could not be parsed as date.");
213 switch (errorData.
type()) {
216 error = c->
translate(
"Cutelyst::ValidatorBefore",
"The value in the “%1” field could not be parsed as date and time.").
arg(_label);
220 error = c->
translate(
"Cutelyst::ValidatorBefore",
"The value in the “%1” field could not be parsed as time.").
arg(_label);
224 error = c->
translate(
"Cutelyst::ValidatorBefore",
"The value in the “%1” field could not be parsed as date.").
arg(_label);