19 #include <QStringList> 44 if ( !mValid && !other.mValid )
46 else if ( mValid && other.mValid )
55 QRegExp rx(
"([-+]?\\d?\\.?\\d+\\s+\\S+)", Qt::CaseInsensitive );
59 while (( pos = rx.
indexIn(
string, pos ) ) != -1 )
66 map.
insert( 1,
QStringList() <<
"second" <<
"seconds" <<
QObject::tr(
"second|seconds",
"list of words separated by | which reference years" ).split(
'|' ) );
67 map.
insert( 0 +
MINUTE,
QStringList() <<
"minute" <<
"minutes" <<
QObject::tr(
"minute|minutes",
"list of words separated by | which reference minutes" ).split(
'|' ) );
68 map.
insert( 0 +
HOUR,
QStringList() <<
"hour" <<
"hours" <<
QObject::tr(
"hour|hours",
"list of words separated by | which reference minutes hours" ).split(
'|' ) );
74 Q_FOREACH (
const QString& match, list )
78 double value = split.
at( 0 ).toDouble( &ok );
88 int duration = it.
key();
91 if ( match.
contains( name, Qt::CaseInsensitive ) )
100 seconds += value * duration;
116 dbg.
nospace() <<
"QgsInterval()";
124 qint64 mSeconds = dt2.
msecsTo( dt1 );
130 return start.
addMSecs( static_cast<qint64>( interval.
seconds() * 1000.0 ) );
135 qint64
seconds =
static_cast< qint64
>( date2.
daysTo( date1 ) ) * 24 * 60 * 60;
141 qint64 mSeconds = time2.
msecsTo( time1 );
static const int YEARS
Seconds per year (average)
int daysTo(const QDate &d) const
QString cap(int nth) const
bool isValid() const
Returns true if the interval is valid.
static const int MONTHS
Seconds per month, based on 30 day month.
QgsInterval()
Default constructor for QgsInterval.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
const_iterator constBegin() const
const T & at(int i) const
double seconds() const
Returns the interval duration in seconds.
static QgsInterval fromString(const QString &string)
Converts a string to an interval.
int msecsTo(const QTime &t) const
QString tr(const char *sourceText, const char *disambiguation, int n)
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
int matchedLength() const
static const int HOUR
Seconds per hour.
int indexIn(const QString &str, int offset, CaretMode caretMode) const
static const int WEEKS
Seconds per week.
const_iterator constEnd() const
static const int DAY
Seconds per day.
bool contains(QChar ch, Qt::CaseSensitivity cs) const
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.
QDateTime operator+(const QDateTime &start, const QgsInterval &interval)
Adds an interval to a datetime.
bool operator==(const QgsInterval &other) const
static const int MINUTE
Seconds per minute.
iterator insert(const Key &key, const T &value)
qint64 msecsTo(const QDateTime &other) const
QDateTime addMSecs(qint64 msecs) const