Added overload for CheckSpecialDay().
Added helpers SpecialDaysWorkTimeFrom() and SpecialDaysWorkTimeUntil().
This commit is contained in:
		@@ -1,6 +1,8 @@
 | 
			
		||||
#include "utilities.h"
 | 
			
		||||
#include "tariff_log.h"
 | 
			
		||||
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
 | 
			
		||||
static int protection_counter = 0;
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
@@ -271,3 +273,47 @@ bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeS
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Utilities::CheckSpecialDay(Configuration const *cfg,
 | 
			
		||||
                                QDateTime const ¤tDateTime,
 | 
			
		||||
                                int* specialDayId,
 | 
			
		||||
                                uint32_t *specialDayPrice) {
 | 
			
		||||
    *specialDayId = -1;
 | 
			
		||||
    *specialDayPrice = 0;
 | 
			
		||||
 | 
			
		||||
    std::multimap<int, ATBSpecialDays>::const_iterator spec_days_itr;
 | 
			
		||||
 | 
			
		||||
    for (spec_days_itr = cfg->SpecialDays.cbegin(); spec_days_itr != cfg->SpecialDays.cend(); ++spec_days_itr) {
 | 
			
		||||
        int repeat_every_year = spec_days_itr->second.ped_year;
 | 
			
		||||
        QDate start = QDate::fromString(spec_days_itr->second.ped_date_start.c_str(), Qt::ISODate);
 | 
			
		||||
        QDate end = QDate::fromString(spec_days_itr->second.ped_date_end.c_str(), Qt::ISODate);
 | 
			
		||||
        if (start.isValid() && end.isValid()) {
 | 
			
		||||
            if ((currentDateTime.date().month() >= start.month()) &&
 | 
			
		||||
                (currentDateTime.date().month() <= end.month())) {
 | 
			
		||||
                if ((currentDateTime.date().day() >= start.day()) &&
 | 
			
		||||
                    (currentDateTime.date().day() <= end.day())) {
 | 
			
		||||
                    if (repeat_every_year <= 0) {
 | 
			
		||||
                        if ((currentDateTime.date().year() != start.year()) ||
 | 
			
		||||
                            (currentDateTime.date().year() != end.year())) {
 | 
			
		||||
                            continue;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    qDebug() << "CheckSpecialDay() => SPECIAL DAY";
 | 
			
		||||
                    *specialDayId = spec_days_itr->second.ped_id;
 | 
			
		||||
                    *specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price;
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QTime Utilities::SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId) {
 | 
			
		||||
    return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_from.c_str(), Qt::ISODate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QTime Utilities::SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId) {
 | 
			
		||||
    return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_to.c_str(), Qt::ISODate);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user