Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb51792' into 'master'
[buteo-syncfw] Fix interval-scheduling check. Contributes to JB#51792

See merge request mer-core/buteo-syncfw!57
  • Loading branch information
chriadam committed Nov 12, 2020
2 parents 40cc79a + 41828f9 commit c91449b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
22 changes: 8 additions & 14 deletions libbuteosyncfw/profile/SyncSchedule.cpp
Expand Up @@ -286,7 +286,7 @@ bool SyncSchedule::inExternalSyncRushPeriod(const QDateTime &aDateTime) const
return false;
}

QDateTime SyncSchedule::nextSyncTime(const QDateTime &aPrevSync) const
QDateTime SyncSchedule::nextSyncTime(const QDateTime &aPrevSync) const
{
FUNCTION_CALL_TRACE;

Expand Down Expand Up @@ -361,17 +361,10 @@ QDateTime SyncSchedule::nextSyncTime(const QDateTime &aPrevSync) const
}

} else {
int numberOfIntervals = 0;
if(0 != d_ptr->iInterval)
{
int secs = reference.secsTo(now) + 1;
numberOfIntervals = secs/(d_ptr->iInterval * 60);
if(secs % (d_ptr->iInterval * 60))
{
numberOfIntervals++;
}
LOG_DEBUG("numberOfInterval:"<<numberOfIntervals<<"interval time"<<d_ptr->iInterval);
}
const int secs = reference.secsTo(now) + 1;
const int numberOfIntervals = (secs/(d_ptr->iInterval * 60))
+ (((secs % (d_ptr->iInterval * 60)) != 0) ? 1 : 0);
LOG_DEBUG("numberOfInterval:"<<numberOfIntervals<<"interval time"<<d_ptr->iInterval);
nextSync = reference.addSecs(numberOfIntervals * d_ptr->iInterval * 60);
}
}
Expand Down Expand Up @@ -580,11 +573,12 @@ bool SyncSchedule::isSyncScheduled(const QDateTime &aActualDateTime, const QDate
longInterval = reference.secsTo(nextSync) / 60;
}

unsigned interval = longInterval > 0
const unsigned int interval = longInterval > 0
? (longInterval > UINT_MAX ? UINT_MAX : static_cast<unsigned int>(longInterval))
: d_ptr->iInterval;

return reference.secsTo(aActualDateTime) > ((interval - 10) * 60);
// avoid wrap-around: don't subtract from unsigned interval
return reference.secsTo(aActualDateTime) > (interval * 60);
}

DaySet SyncSchedulePrivate::parseDays(const QString &aDays) const
Expand Down
4 changes: 2 additions & 2 deletions libbuteosyncfw/profile/SyncSchedule_p.h
Expand Up @@ -87,7 +87,7 @@ class SyncSchedulePrivate
QDateTime iScheduleConfiguredTime;

//! Time interval
unsigned iInterval;
unsigned int iInterval;

bool iEnabled;

Expand All @@ -103,7 +103,7 @@ class SyncSchedulePrivate
QTime iRushEnd;

//! Rush Hour Time interval
unsigned iRushInterval;
unsigned int iRushInterval;

//! Indicates if Rush Hour is Enabled
bool iRushEnabled;
Expand Down

0 comments on commit c91449b

Please sign in to comment.