MOBILISIS-Calculator/main/main.cpp.bck.23112023

76 lines
2.5 KiB
Plaintext
Raw Permalink Normal View History

#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 "calculator_functions.h"
#include "payment_method.h"
#include "payment_option.h"
#include <QDebug>
#include <QDateTime>
static Calculator calculator;
int main() {
parking_tariff_t *tariff = 0;
if (init_tariff(&tariff, "/tmp"))
{
for(auto itr = tariff->WeekDaysWorktime.begin(); itr != tariff->WeekDaysWorktime.end(); ++itr)
{
qCritical() << itr->first << "TO " << itr->second.pwd_time_from.c_str();
qCritical() << itr->first << "FROM" << itr->second.pwd_time_from.c_str();
}
for (auto[itr, rangeEnd] = tariff->WeekDaysWorktime.equal_range(36); itr != rangeEnd; ++itr)
{
qCritical() << itr->first << itr->second.pwd_time_from.c_str();
}
#if 0
struct price_t price;
memset(&price, 0x00, sizeof(price));
QDateTime start = QDateTime::fromString("2023-11-22T14:00:00.000Z",Qt::ISODate); //QDateTime::currentDateTime();
//QDateTime start = QDateTime::currentDateTime();
for (int j=30; j <=180; j+=5) {
QDateTime s = start.addSecs(j*60);
for (int i = 60; i <= 360; i+=10) {
std::string a = calculator.GetDurationFromCost(tariff, PaymentOption::Option1,
s.toString(Qt::ISODate).toStdString().c_str(),
i);
//qCritical() << "cost=" << i << ", duration=" << QString(a.c_str());
}
}
#endif
free_tariff(tariff);
}
return 0;
}