MOBILISIS-Calculator/main/main.cpp

62 lines
2.1 KiB
C++

#ifdef WIN32
#include <time.h>
#include <iomanip>
#include <sstream>
extern "C" char* strptime(const char* s,
const char* f,
struct tm* tm) {
// Isn't the C++ standard lib nice? std::get_time is defined such that its
// format parameters are the exact same as strptime. Of course, we have to
// create a string stream first, and imbue it with the current C locale, and
// we also have to make sure we return the right things if it fails, or
// if it succeeds, but this is still far simpler an implementation than any
// of the versions in any of the C standard libraries.
std::istringstream input(s);
input.imbue(std::locale(setlocale(LC_ALL, nullptr)));
input >> std::get_time(tm, f);
if (input.fail()) {
return nullptr;
}
return (char*)(s + input.tellg());
}
#endif
#include "calculate_price.h"
#include <QDebug>
#include <QDateTime>
int main() {
parking_tariff_t *tariff = 0;
if (init_tariff(&tariff, "/tmp"))
{
struct price_t price;
memset(&price, 0x00, sizeof(price));
// QDateTime start = QDateTime::fromString("2023-06-01T07:50:00.000Z",Qt::ISODate); //QDateTime::currentDateTime();
QDateTime start = QDateTime::currentDateTime();
time_t start_parking_time = start.toSecsSinceEpoch() / 60;
// int timeSteps[9] = {60, 180, 1440, 2880, 4320, 5670, 7200, 8640, 10080};
int timeSteps[3] = {60, 180, 1440};
for (int i = 0 ; i < 3; ++i) {
time_t end_parking_time = start_parking_time + timeSteps[i];
if (compute_price_for_parking_ticket(tariff,
start_parking_time,
end_parking_time,
&price))
{
qDebug() << "GetCostFromDuration() time: " << timeSteps[i] << "price=" << price.netto;
}
}
free_tariff(tariff);
}
return 0;
}