plugins/nightlight: Ensure the target temperature remains within reasonable bounds
The interpolated temperature can get out of the bounds of [target1, target2] if the current time is slightly earlier than m_prev.first, which can be unexpected. This change addresses that by adding a relevant guard.
This commit is contained in:
parent
21a45c2700
commit
f46174453d
1 changed files with 10 additions and 8 deletions
|
@ -609,16 +609,18 @@ int NightLightManager::currentTargetTemp() const
|
|||
const QDateTime todayNow = QDateTime::currentDateTime();
|
||||
|
||||
auto f = [this, todayNow](int target1, int target2) {
|
||||
if (todayNow < m_prev.second) {
|
||||
double residueQuota = todayNow.msecsTo(m_prev.second) / (double)m_prev.first.msecsTo(m_prev.second);
|
||||
|
||||
double ret = (int)((1. - residueQuota) * (double)target2 + residueQuota * (double)target1);
|
||||
// remove single digits
|
||||
ret = ((int)(0.1 * ret)) * 10;
|
||||
return (int)ret;
|
||||
} else {
|
||||
if (todayNow <= m_prev.first) {
|
||||
return target1;
|
||||
}
|
||||
if (todayNow >= m_prev.second) {
|
||||
return target2;
|
||||
}
|
||||
|
||||
double residueQuota = todayNow.msecsTo(m_prev.second) / (double)m_prev.first.msecsTo(m_prev.second);
|
||||
double ret = (int)((1. - residueQuota) * (double)target2 + residueQuota * (double)target1);
|
||||
// remove single digits
|
||||
ret = ((int)(0.1 * ret)) * 10;
|
||||
return (int)ret;
|
||||
};
|
||||
|
||||
if (daylight()) {
|
||||
|
|
Loading…
Reference in a new issue