6 #include "validatorbefore_p.h"
8 #include <QtCore/QLoggingCategory>
15 const char *inputFormat,
39 const QTimeZone tz = d->extractTimeZone(c, params, d->timeZone);
43 ? d->extractOtherDateTime(c, params, d->comparison.toString(), tz, d->inputFormat)
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;
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;
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;
116 qCWarning(C_VALIDATOR).noquote()
117 <<
debugString(c) <<
"Invalid comparison data:" << d->comparison;
137 return c->
qtTrId(
"cutelyst-valbefore-genvalerr-date")
142 return c->
qtTrId(
"cutelyst-valbefore-genvalerr-dt")
147 return c->
qtTrId(
"cutelyst-valbefore-genvalerr-time")
159 return c->
qtTrId(
"cutelyst-valbefore-genvalerr-date-label")
165 return c->
qtTrId(
"cutelyst-valbefore-genvalerr-dt-label")
170 return c->
qtTrId(
"cutelyst-valbefore-genvalerr-time-label")
184 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-dt");
186 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-dt-label").
arg(_label);
197 if (d->inputFormat) {
198 const QString _inputFormatTranslated =
199 d->translationContext ? c->
translate(d->translationContext, d->inputFormat)
200 : c->
qtTrId(d->inputFormat);
202 return c->
qtTrId(
"cutelyst-validator-genparseerr-dt-format")
203 .
arg(_inputFormatTranslated);
205 return c->
qtTrId(
"cutelyst-validator-genparseerr-dt-format-label")
206 .
arg(_label, _inputFormatTranslated);
213 return c->
qtTrId(
"cutelyst-validator-genparseerr-dt");
215 return c->
qtTrId(
"cutelyst-validator-genparseerr-time");
217 return c->
qtTrId(
"cutelyst-validator-genparseerr-date");
224 return c->
qtTrId(
"cutelyst-vaidator-genparseerr-dt-label").
arg(_label);
226 return c->
qtTrId(
"cutelyst-validator-genparseerr-time-label").
arg(_label);
228 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
Checks if a date, time or datetime is before a comparison value.
ValidatorBefore(const QString &field, const QVariant &comparison, const QString &timeZone=QString(), const char *inputFormat=nullptr, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
QString genericValidationDataError(Context *c, const QVariant &errorData=QVariant()) const override
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
~ValidatorBefore() override
QString genericParsingError(Context *c, const QVariant &errorData=QVariant()) const override
Base class for all validator rules.
QString validationError(Context *c, const QVariant &errorData={}) const
QString label(Context *c) const
QString validationDataError(Context *c, const QVariant &errorData={}) const
void defaultValue(Context *c, ValidatorReturnType *result) const
QString value(const ParamsMultiMap ¶ms) const
QString parsingError(Context *c, const QVariant &errorData={}) const
QString debugString(Context *c) const
The Cutelyst namespace holds all public Cutelyst API.
bool isValid(int year, int month, int day)
bool isValid() const const
QString toString(QDate date, QLocale::FormatType format) const const
QString arg(Args &&... args) const const
bool isEmpty() const const
bool isValid(int h, int m, int s, int ms)
void setValue(QVariant &&value)
QDate toDate() const const
QDateTime toDateTime() const const
QTime toTime() const const
int userType() const const
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.