6 #include "validatorbefore_p.h" 8 #include <QtCore/QLoggingCategory> 12 Q_LOGGING_CATEGORY(C_VALIDATORBEFORE,
"cutelyst.utils.validator.before", QtWarningMsg)
17 const
char *inputFormat,
43 const QTimeZone tz = d->extractTimeZone(c, params, d->timeZone);
47 ? d->extractOtherDateTime(c, params, d->comparison.toString(), tz, d->inputFormat)
53 if (Q_UNLIKELY(!odate.
isValid())) {
56 "ValidatorBefore: Invalid comparison date and time for field %s at %s::%s.",
58 qPrintable(c->controllerName()),
59 qPrintable(c->actionName()));
62 const QDate date = d->extractDate(c, v, d->inputFormat);
63 if (Q_UNLIKELY(!date.
isValid())) {
66 "ValidatorBefore: Can not parse input date \"%s\" for field %s at %s::%s.",
69 qPrintable(c->controllerName()),
70 qPrintable(c->actionName()));
73 if (Q_UNLIKELY(date >= odate)) {
75 "ValidatorBefore: Validation failed at %s::%s for field %s: Input " 76 "date \"%s\" is not before \"%s\".",
77 qPrintable(c->controllerName()),
78 qPrintable(c->actionName()),
92 if (Q_UNLIKELY(!odatetime.
isValid())) {
95 "ValidatorBefore: Invalid comparison date and time for field %s at %s::%s.",
97 qPrintable(c->controllerName()),
98 qPrintable(c->actionName()));
101 const QDateTime datetime = d->extractDateTime(c, v, d->inputFormat, tz);
102 if (Q_UNLIKELY(!datetime.
isValid())) {
103 qCWarning(C_VALIDATOR,
104 "ValidatorBefore: Can not parse input date and time \"%s\" for field " 108 qPrintable(c->controllerName()),
109 qPrintable(c->actionName()));
112 if (Q_UNLIKELY(datetime >= odatetime)) {
114 "ValidatorBefore: Validation failed at %s::%s for field %s: Input " 115 "date and time \"%s\" is not before \"%s\".",
116 qPrintable(c->controllerName()),
117 qPrintable(c->actionName()),
131 if (Q_UNLIKELY(!otime.
isValid())) {
132 qCWarning(C_VALIDATOR,
133 "ValidatorBefore: Invalid comparison time for field %s at %s::%s.",
135 qPrintable(c->controllerName()),
136 qPrintable(c->actionName()));
139 const QTime time = d->extractTime(c, v, d->inputFormat);
140 if (Q_UNLIKELY(!time.
isValid())) {
143 "ValidatorBefore: Can not parse input time \"%s\" for field %s at %s::%s.",
146 qPrintable(c->controllerName()),
147 qPrintable(c->actionName()));
150 if (Q_UNLIKELY(time >= otime)) {
152 "ValidatorBefore: Validation failed at %s::%s for field %s: Input " 153 "time \"%s\" is not before \"%s\".",
154 qPrintable(c->controllerName()),
155 qPrintable(c->actionName()),
167 qCWarning(C_VALIDATOR)
168 <<
"ValidatorBefore: Invalid validation data for field" <<
field() <<
"at" 169 << c->controllerName() <<
"::" << c->actionName() <<
":" << d->comparison;
190 QStringLiteral(
"Has to be before %1.")
194 error = QStringLiteral(
"Has to be before %1.")
200 QStringLiteral(
"Has to be before %1.")
213 c->
translate(
"Cutelyst::ValidatorBefore",
214 "The date in the “%1” field must be before %2.")
219 error = c->
translate(
"Cutelyst::ValidatorBefore",
220 "The date and time in the “%1” field must be before %2.")
227 c->
translate(
"Cutelyst::ValidatorBefore",
228 "The time in the “%1” field must be before %2.")
247 c->
translate(
"Cutelyst::ValidatorBefore",
248 "The comparison value is not a valid date and/or time, or cannot be found.");
260 if (d->inputFormat) {
265 "Cutelyst::ValidatorBefore",
266 "Could not be parsed according to the following date and/or time format: %1")
267 .
arg(c->
translate(d->translationContext.data(), d->inputFormat));
270 error = c->
translate(
"Cutelyst::ValidatorBefore",
271 "The value of the “%1” field could not be parsed according to the " 272 "following date and/or time format: %2")
273 .
arg(_label, c->
translate(d->translationContext.data(), d->inputFormat));
280 error = c->
translate(
"Cutelyst::ValidatorBefore",
281 "Could not be parsed as date and time.");
284 error = c->
translate(
"Cutelyst::ValidatorBefore",
"Could not be parsed as time.");
287 error = c->
translate(
"Cutelyst::ValidatorBefore",
"Could not be parsed as date.");
298 "Cutelyst::ValidatorBefore",
299 "The value in the “%1” field could not be parsed as date and time.")
304 error = c->
translate(
"Cutelyst::ValidatorBefore",
305 "The value in the “%1” field could not be parsed as time.")
310 error = c->
translate(
"Cutelyst::ValidatorBefore",
311 "The value in the “%1” field could not be parsed as date.")
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error if validation failed.
QString toString(QStringView format, QCalendar cal) const const
QString parsingError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if an error occurred while parsing input.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
QString toString(QStringView format) const const
QString toString(QStringView format, QCalendar cal) const const
Stores custom error messages and the input field label.
QDateTime toDateTime() const const
QTime toTime() const const
bool isValid(int year, int month, int day)
bool isEmpty() const const
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
QString genericValidationDataError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error if comparison data was invalid.
bool isValid(int h, int m, int s, int ms)
QString validationDataError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if any validation data is missing or invalid.
The Cutelyst namespace holds all public Cutelyst API.
Base class for all validator rules.
Checks if a date, time or datetime is before a comparison value.
QLocale locale() const noexcept
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
int userType() const const
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
bool isValid() const const
QDate toDate() const const
QString field() const
Returns the name of the field to validate.
Contains the result of a single input parameter validation.
~ValidatorBefore() override
Deconstructs the before validator.
QString genericParsingError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error if the input value could not be parsed.
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
Performs the validation and returns the result.
QString arg(Args &&... args) const const
void defaultValue(Context *c, ValidatorReturnType *result, const char *validatorName) const
I a defValKey has been set in the constructor, this will try to get the default value from the stash ...
void setValue(QVariant &&value)