19 #include <QStringList> 
   24 #include <QRegularExpression> 
   35   , mOriginalDuration( seconds )
 
   43   , mOriginalDuration( duration )
 
   44   , mOriginalUnit( unit )
 
   48 QgsInterval::QgsInterval( 
double years, 
double months, 
double weeks, 
double days, 
double hours, 
double minutes, 
double seconds )
 
   60     mOriginalDuration = 
years;
 
   65     mOriginalDuration = 
months;
 
   70     mOriginalDuration = 
weeks;
 
   75     mOriginalDuration = 
days;
 
   80     mOriginalDuration = 
hours;
 
   95     mOriginalDuration = 0;
 
  107     return mOriginalDuration;
 
  109   return mSeconds / 
YEARS;
 
  116   mOriginalDuration = 
years;
 
  123     return mOriginalDuration;
 
  132   mOriginalDuration = 
months;
 
  139     return mOriginalDuration;
 
  141   return mSeconds / 
WEEKS;
 
  149   mOriginalDuration = 
weeks;
 
  156     return mOriginalDuration;
 
  158   return mSeconds / 
DAY;
 
  166   mOriginalDuration = 
days;
 
  173     return mOriginalDuration;
 
  175   return mSeconds / 
HOUR;
 
  183   mOriginalDuration = 
hours;
 
  190     return mOriginalDuration;
 
  214   const thread_local QRegularExpression rx( 
"([-+]?\\d*\\.?\\d+\\s+\\S+)", QRegularExpression::CaseInsensitiveOption );
 
  215   const thread_local QRegularExpression rxtime( 
".* \\d{1,2}(:)\\d{1,2}(:)\\d{1,2}.*", QRegularExpression::CaseInsensitiveOption );
 
  217   const QRegularExpressionMatch matchtime = rxtime.match( 
string );
 
  218   QString modedString = QString( 
string );
 
  219   if ( matchtime.hasMatch() ) 
 
  222     modedString.replace( matchtime.capturedStart( 2 ), 1, 
" minutes " );
 
  224     modedString.replace( matchtime.capturedStart( 1 ), 1, 
" hours " );
 
  225     modedString.append( 
" seconds" );
 
  230   QRegularExpressionMatch match = rx.match( modedString );
 
  231   while ( match.hasMatch() )
 
  233     list << match.captured( 1 );
 
  234     pos = match.capturedStart() + match.capturedLength();
 
  235     match = rx.match( modedString, pos );
 
  238   const thread_local QMap<int, QStringList> map{{
 
  239       {1, QStringList() << QStringLiteral( 
"second" ) << QStringLiteral( 
"seconds" ) << QObject::tr( 
"second|seconds", 
"list of words separated by | which reference years" ).split( 
'|' )},
 
  240       { 0 + 
MINUTE, QStringList() << QStringLiteral( 
"minute" ) << QStringLiteral( 
"minutes" ) << QObject::tr( 
"minute|minutes", 
"list of words separated by | which reference minutes" ).split( 
'|' ) },
 
  241       {0 + 
HOUR, QStringList() << QStringLiteral( 
"hour" ) << QStringLiteral( 
"hours" ) << QObject::tr( 
"hour|hours", 
"list of words separated by | which reference minutes hours" ).split( 
'|' )},
 
  242       {0 + 
DAY, QStringList() << QStringLiteral( 
"day" ) << QStringLiteral( 
"days" ) << QObject::tr( 
"day|days", 
"list of words separated by | which reference days" ).split( 
'|' )},
 
  243       {0 + 
WEEKS, QStringList() << QStringLiteral( 
"week" ) << QStringLiteral( 
"weeks" ) << QObject::tr( 
"week|weeks", 
"wordlist separated by | which reference weeks" ).split( 
'|' )},
 
  244       {0 + 
MONTHS, QStringList() << QStringLiteral( 
"month" ) << QStringLiteral( 
"months" ) << QStringLiteral( 
"mon" ) << QObject::tr( 
"month|months|mon", 
"list of words separated by | which reference months" ).split( 
'|' )},
 
  245       {0 + 
YEARS, QStringList() << QStringLiteral( 
"year" ) << QStringLiteral( 
"years" ) << QObject::tr( 
"year|years", 
"list of words separated by | which reference years" ).split( 
'|' )},
 
  248   const thread_local QRegularExpression splitRx( 
"\\s+" );
 
  250   for ( 
const QString &match : std::as_const( list ) )
 
  252     const QStringList split = match.split( splitRx );
 
  254     const double value = split.at( 0 ).toDouble( &ok );
 
  260     bool matched = 
false;
 
  261     QMap<int, QStringList>::const_iterator it = map.constBegin();
 
  262     for ( ; it != map.constEnd(); ++it )
 
  264       const int duration = it.key();
 
  265       const QStringList durationIdentifiers = it.value();
 
  266       for ( 
const QString &identifier : durationIdentifiers )
 
  268         if ( match.contains( identifier, Qt::CaseInsensitive ) )
 
  293     dbg.nospace() << 
"QgsInterval()";
 
  295     dbg.nospace() << 
"QgsInterval(" << interval.
seconds() << 
")";
 
  296   return dbg.maybeSpace();
 
  301   const qint64 mSeconds = dt2.msecsTo( dt1 );
 
  307   return start.addMSecs( 
static_cast<qint64
>( interval.
seconds() * 1000.0 ) );
 
  312   const qint64 seconds = 
static_cast< qint64 
>( date2.daysTo( date1 ) ) * 24 * 60 * 60;
 
  318   const qint64 mSeconds = time2.msecsTo( time1 );