19 #include <QStringList> 37 if ( !mValid && !other.mValid )
39 else if ( mValid && other.mValid )
48 QRegExp rx(
"([-+]?\\d*\\.?\\d+\\s+\\S+)", Qt::CaseInsensitive );
52 while ( ( pos = rx.indexIn(
string, pos ) ) != -1 )
55 pos += rx.matchedLength();
58 QMap<int, QStringList> map;
59 map.insert( 1, QStringList() << QStringLiteral(
"second" ) << QStringLiteral(
"seconds" ) << QObject::tr(
"second|seconds",
"list of words separated by | which reference years" ).split(
'|' ) );
60 map.insert( 0 +
MINUTE, QStringList() << QStringLiteral(
"minute" ) << QStringLiteral(
"minutes" ) << QObject::tr(
"minute|minutes",
"list of words separated by | which reference minutes" ).split(
'|' ) );
61 map.insert( 0 +
HOUR, QStringList() << QStringLiteral(
"hour" ) << QStringLiteral(
"hours" ) << QObject::tr(
"hour|hours",
"list of words separated by | which reference minutes hours" ).split(
'|' ) );
62 map.insert( 0 +
DAY, QStringList() << QStringLiteral(
"day" ) << QStringLiteral(
"days" ) << QObject::tr(
"day|days",
"list of words separated by | which reference days" ).split(
'|' ) );
63 map.insert( 0 +
WEEKS, QStringList() << QStringLiteral(
"week" ) << QStringLiteral(
"weeks" ) << QObject::tr(
"week|weeks",
"wordlist separated by | which reference weeks" ).split(
'|' ) );
64 map.insert( 0 +
MONTHS, QStringList() << QStringLiteral(
"month" ) << QStringLiteral(
"months" ) << QObject::tr(
"month|months",
"list of words separated by | which reference months" ).split(
'|' ) );
65 map.insert( 0 +
YEARS, QStringList() << QStringLiteral(
"year" ) << QStringLiteral(
"years" ) << QObject::tr(
"year|years",
"list of words separated by | which reference years" ).split(
'|' ) );
67 Q_FOREACH (
const QString &match, list )
69 QStringList split = match.split( QRegExp(
"\\s+" ) );
71 double value = split.at( 0 ).toDouble( &ok );
78 QMap<int, QStringList>::const_iterator it = map.constBegin();
79 for ( ; it != map.constEnd(); ++it )
81 int duration = it.key();
82 Q_FOREACH (
const QString &name, it.value() )
84 if ( match.contains( name, Qt::CaseInsensitive ) )
93 seconds += value * duration;
109 dbg.nospace() <<
"QgsInterval()";
111 dbg.nospace() <<
"QgsInterval(" << interval.
seconds() <<
")";
112 return dbg.maybeSpace();
117 qint64 mSeconds = dt2.msecsTo( dt1 );
123 return start.addMSecs( static_cast<qint64>( interval.
seconds() * 1000.0 ) );
128 qint64
seconds =
static_cast< qint64
>( date2.daysTo( date1 ) ) * 24 * 60 * 60;
134 qint64 mSeconds = time2.msecsTo( time1 );
static const int YEARS
Seconds per year (average)
bool operator==(QgsInterval other) const
bool isValid() const
Returns true if the interval is valid.
static const int MONTHS
Seconds per month, based on 30 day month.
double seconds() const
Returns the interval duration in seconds.
static QgsInterval fromString(const QString &string)
Converts a string to an interval.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
static const int HOUR
Seconds per hour.
static const int WEEKS
Seconds per week.
QDateTime operator+(const QDateTime &start, QgsInterval interval)
static const int DAY
Seconds per day.
QgsInterval operator-(const QDateTime &dt1, const QDateTime &dt2)
Returns the interval between two datetimes.
QDebug operator<<(QDebug dbg, const QgsInterval &interval)
Debug string representation of interval.
A representation of the interval between two datetime values.
static const int MINUTE
Seconds per minute.
QgsInterval()=default
Default constructor for QgsInterval.