25#include <QtCore/QDateTime>
32 auto secsSince = early.
secsTo(late);
35 return SafeString(QStringLiteral(
"0 minutes"));
39 singularNames << QStringLiteral(
"year") << QStringLiteral(
"month")
40 << QStringLiteral(
"week") << QStringLiteral(
"day")
41 << QStringLiteral(
"hour") << QStringLiteral(
"minute");
44 pluralNames << QStringLiteral(
"years") << QStringLiteral(
"months")
45 << QStringLiteral(
"weeks") << QStringLiteral(
"days")
46 << QStringLiteral(
"hours") << QStringLiteral(
"minutes");
49 seconds << (60 * 60 * 24 * 365)
50 << (60 * 60 * 24 * 30)
56 auto count = secsSince;
58 while (i < seconds.
size()) {
59 count = (secsSince / seconds.
at(i));
68 QStringLiteral(
"%1 %2").arg(count).arg(pluralNames.
at(i - 1)));
71 QStringLiteral(
"%1 %2").arg(count).arg(singularNames.
at(i - 1)));
73 if (seconds.
size() > i) {
74 auto count2 = (secsSince - (seconds.
at(i - 1) * count)) / seconds.
at(i);
78 QStringLiteral(
", %1 %2").arg(count2).arg(pluralNames.
at(i)));
81 QStringLiteral(
", %1 %2").arg(count2).arg(singularNames.
at(i)));
88 bool autoescape)
const
99#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
108 if (!argString.get().isEmpty())
111 return d.
toString(QStringLiteral(
"MMM. d, yyyy"));
115 bool autoescape)
const
126#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
139 bool autoescape)
const
143 if (argument.
userType() != qMetaTypeId<QDateTime>())
151 return timeSince(early, late);
156 bool autoescape)
const
160 if (argument.
userType() != qMetaTypeId<QDateTime>())
168 return timeSince(early, late);
A QString wrapper class for containing whether a string is safe or needs to be escaped.
QVariant doFilter(const QVariant &input, const QVariant &argument={}, bool autoescape={}) const override
QVariant doFilter(const QVariant &input, const QVariant &argument={}, bool autoescape={}) const override
QVariant doFilter(const QVariant &input, const QVariant &argument={}, bool autoescape={}) const override
QVariant doFilter(const QVariant &input, const QVariant &argument={}, bool autoescape={}) const override
Cutelee::SafeString getSafeString(const QVariant &input)
QDateTime currentDateTime()
QDateTime fromString(const QString &string, Qt::DateFormat format)
bool isValid() const const
qint64 secsTo(const QDateTime &other) const const
void setDate(const QDate &date)
void setTime(const QTime &time)
QString toString(Qt::DateFormat format) const const
const T & at(int i) const const
QString & append(QChar ch)
QDate toDate() const const
QDateTime toDateTime() const const
QTime toTime() const const
int userType() const const
Utility functions used throughout Cutelee.