19 #include <QStringList>
43 QgsInterval::QgsInterval(
double years,
double months,
double weeks,
double days,
double hours,
double minutes,
double seconds )
58 if ( !mValid && !other.mValid )
60 else if ( mValid && other.mValid )
69 QRegExp rx(
"([-+]?\\d*\\.?\\d+\\s+\\S+)", Qt::CaseInsensitive );
73 while ( ( pos = rx.indexIn(
string, pos ) ) != -1 )
76 pos += rx.matchedLength();
79 QMap<int, QStringList> map;
80 map.insert( 1, QStringList() << QStringLiteral(
"second" ) << QStringLiteral(
"seconds" ) << QObject::tr(
"second|seconds",
"list of words separated by | which reference years" ).split(
'|' ) );
81 map.insert( 0 +
MINUTE, QStringList() << QStringLiteral(
"minute" ) << QStringLiteral(
"minutes" ) << QObject::tr(
"minute|minutes",
"list of words separated by | which reference minutes" ).split(
'|' ) );
82 map.insert( 0 +
HOUR, QStringList() << QStringLiteral(
"hour" ) << QStringLiteral(
"hours" ) << QObject::tr(
"hour|hours",
"list of words separated by | which reference minutes hours" ).split(
'|' ) );
83 map.insert( 0 +
DAY, QStringList() << QStringLiteral(
"day" ) << QStringLiteral(
"days" ) << QObject::tr(
"day|days",
"list of words separated by | which reference days" ).split(
'|' ) );
84 map.insert( 0 +
WEEKS, QStringList() << QStringLiteral(
"week" ) << QStringLiteral(
"weeks" ) << QObject::tr(
"week|weeks",
"wordlist separated by | which reference weeks" ).split(
'|' ) );
85 map.insert( 0 +
MONTHS, QStringList() << QStringLiteral(
"month" ) << QStringLiteral(
"months" ) << QObject::tr(
"month|months",
"list of words separated by | which reference months" ).split(
'|' ) );
86 map.insert( 0 +
YEARS, QStringList() << QStringLiteral(
"year" ) << QStringLiteral(
"years" ) << QObject::tr(
"year|years",
"list of words separated by | which reference years" ).split(
'|' ) );
88 const auto constList = list;
89 for (
const QString &match : constList )
91 QStringList split = match.split( QRegExp(
"\\s+" ) );
93 double value = split.at( 0 ).toDouble( &ok );
100 QMap<int, QStringList>::const_iterator it = map.constBegin();
101 for ( ; it != map.constEnd(); ++it )
103 int duration = it.key();
104 const auto constValue = it.value();
105 for (
const QString &name : constValue )
107 if ( match.contains( name, Qt::CaseInsensitive ) )
132 dbg.nospace() <<
"QgsInterval()";
134 dbg.nospace() <<
"QgsInterval(" << interval.
seconds() <<
")";
135 return dbg.maybeSpace();
140 qint64 mSeconds = dt2.msecsTo( dt1 );
146 return start.addMSecs(
static_cast<qint64
>( interval.
seconds() * 1000.0 ) );
151 qint64 seconds =
static_cast< qint64
>( date2.daysTo( date1 ) ) * 24 * 60 * 60;
157 qint64 mSeconds = time2.msecsTo( time1 );