19 #include <QStringList> 38 if ( !mValid && !other.mValid )
40 else if ( mValid && other.mValid )
49 QRegExp rx(
"([-+]?\\d*\\.?\\d+\\s+\\S+)", Qt::CaseInsensitive );
53 while ( ( pos = rx.indexIn(
string, pos ) ) != -1 )
56 pos += rx.matchedLength();
59 QMap<int, QStringList> map;
60 map.insert( 1, QStringList() << QStringLiteral(
"second" ) << QStringLiteral(
"seconds" ) << QObject::tr(
"second|seconds",
"list of words separated by | which reference years" ).split(
'|' ) );
61 map.insert( 0 +
MINUTE, QStringList() << QStringLiteral(
"minute" ) << QStringLiteral(
"minutes" ) << QObject::tr(
"minute|minutes",
"list of words separated by | which reference minutes" ).split(
'|' ) );
62 map.insert( 0 +
HOUR, QStringList() << QStringLiteral(
"hour" ) << QStringLiteral(
"hours" ) << QObject::tr(
"hour|hours",
"list of words separated by | which reference minutes hours" ).split(
'|' ) );
63 map.insert( 0 +
DAY, QStringList() << QStringLiteral(
"day" ) << QStringLiteral(
"days" ) << QObject::tr(
"day|days",
"list of words separated by | which reference days" ).split(
'|' ) );
64 map.insert( 0 +
WEEKS, QStringList() << QStringLiteral(
"week" ) << QStringLiteral(
"weeks" ) << QObject::tr(
"week|weeks",
"wordlist separated by | which reference weeks" ).split(
'|' ) );
65 map.insert( 0 +
MONTHS, QStringList() << QStringLiteral(
"month" ) << QStringLiteral(
"months" ) << QObject::tr(
"month|months",
"list of words separated by | which reference months" ).split(
'|' ) );
66 map.insert( 0 +
YEARS, QStringList() << QStringLiteral(
"year" ) << QStringLiteral(
"years" ) << QObject::tr(
"year|years",
"list of words separated by | which reference years" ).split(
'|' ) );
68 Q_FOREACH (
const QString &match, list )
70 QStringList split = match.split( QRegExp(
"\\s+" ) );
72 double value = split.at( 0 ).toDouble( &ok );
79 QMap<int, QStringList>::const_iterator it = map.constBegin();
80 for ( ; it != map.constEnd(); ++it )
82 int duration = it.key();
83 Q_FOREACH (
const QString &name, it.value() )
85 if ( match.contains( name, Qt::CaseInsensitive ) )
94 seconds += value * duration;
110 dbg.nospace() <<
"QgsInterval()";
112 dbg.nospace() <<
"QgsInterval(" << interval.
seconds() <<
")";
113 return dbg.maybeSpace();
118 qint64 mSeconds = dt2.msecsTo( dt1 );
124 return start.addMSecs( static_cast<qint64>( interval.
seconds() * 1000.0 ) );
129 qint64
seconds =
static_cast< qint64
>( date2.daysTo( date1 ) ) * 24 * 60 * 60;
135 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.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
double seconds() const
Returns the interval duration in seconds.
static QgsInterval fromString(const QString &string)
Converts a string to an interval.
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.