Added GetYearPeriodActive() to get active year period.
This commit is contained in:
parent
260973cd09
commit
89b05ffadc
@ -3,6 +3,7 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "day_of_week.h"
|
#include "day_of_week.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
@ -62,6 +63,7 @@ namespace Utilities {
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
bool IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTime);
|
bool IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTime);
|
||||||
bool IsYearPeriodActive(Configuration const *cfg, QDateTime const ¤tDateTime);
|
bool IsYearPeriodActive(Configuration const *cfg, QDateTime const ¤tDateTime);
|
||||||
|
std::optional<ATBPeriodYear> GetYearPeriodActive(Configuration const *cfg, QDateTime const ¤tDateTime);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check permissions
|
/// Check permissions
|
||||||
|
@ -215,6 +215,43 @@ bool Utilities::IsYearPeriodActive(Configuration const *cfg, QDateTime const &dt
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<ATBPeriodYear>
|
||||||
|
Utilities::GetYearPeriodActive(Configuration const *cfg, QDateTime const ¤tDateTime) {
|
||||||
|
|
||||||
|
ATBPeriodYear period;
|
||||||
|
std::optional<ATBPeriodYear> value;
|
||||||
|
|
||||||
|
for (multimap<int, ATBPeriodYear>::const_iterator it = cfg->YearPeriod.cbegin();
|
||||||
|
it != cfg->YearPeriod.cend();
|
||||||
|
++it) {
|
||||||
|
QDate const s(currentDateTime.date().year(), it->second.pye_start_month, it->second.pye_start_day);
|
||||||
|
QDate const e(currentDateTime.date().year(), it->second.pye_end_month, it->second.pye_end_day);
|
||||||
|
|
||||||
|
QDateTime start(currentDateTime);
|
||||||
|
QDateTime end(currentDateTime);
|
||||||
|
|
||||||
|
start.setDate(s);
|
||||||
|
end.setDate(e);
|
||||||
|
|
||||||
|
if (start.date().dayOfYear() < end.date().dayOfYear()) {
|
||||||
|
// start and end in the same year
|
||||||
|
if (currentDateTime.date().dayOfYear() >= start.date().dayOfYear() &&
|
||||||
|
currentDateTime.date().dayOfYear() <= end.date().dayOfYear()) {
|
||||||
|
value = value.value_or(it->second);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (currentDateTime.date().dayOfYear() >= start.date().dayOfYear() ||
|
||||||
|
currentDateTime.date().dayOfYear() <= end.date().dayOfYear()) {
|
||||||
|
value = value.value_or(it->second);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice)
|
bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user