Correction for argument-value of localtime_r()-function
(expects UTC-time instead of local time.)
This commit is contained in:
parent
889fceaae0
commit
69c48e3acc
@ -10,7 +10,12 @@ double total_cost = 0.0f;
|
|||||||
bool overtime = false;
|
bool overtime = false;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
std::string Calculator::GetDurationFromCost(Configuration* cfg, uint8_t payment_option, char const* start_datetime, double price, bool nextDay, bool prepaid)
|
std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||||
|
uint8_t payment_option,
|
||||||
|
char const* start_datetime, // given in local time
|
||||||
|
double price,
|
||||||
|
bool nextDay,
|
||||||
|
bool prepaid)
|
||||||
{
|
{
|
||||||
// Get current date time from input
|
// Get current date time from input
|
||||||
struct tm current_datetime = Utilities::DateTimeToStructTm(start_datetime);
|
struct tm current_datetime = Utilities::DateTimeToStructTm(start_datetime);
|
||||||
@ -266,15 +271,29 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg, uint8_t payment_
|
|||||||
cout << "Total minutes: " << (int)ret_val << endl;
|
cout << "Total minutes: " << (int)ret_val << endl;
|
||||||
if (ret_val <= 0) return "PARKING NOT ALLOWED";
|
if (ret_val <= 0) return "PARKING NOT ALLOWED";
|
||||||
|
|
||||||
struct tm valid_until_datetime = *localtime(&valid_until_datetime_t);
|
#if !defined(_SVID_SOURCE) && !defined(_XOPEN_SOURCE)
|
||||||
// TEST: no daylight saving time
|
// needed for timezone-correction
|
||||||
// valid_until_datetime.tm_isdst = 0;
|
#error "!defined(_SVID_SOURCE) && !defined(_XOPEN_SOURCE)"
|
||||||
|
#else
|
||||||
|
// timezone correction: localtime() needs argument in UTC-timezone
|
||||||
|
// The global variable 'timezone' is set by tzset(), see
|
||||||
|
// https://linux.die.net/man/3/tzset, so I change of the timezone will
|
||||||
|
// also change the value of the variable 'timezone'.
|
||||||
|
valid_until_datetime_t += timezone;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct tm valid_until_datetime;
|
||||||
|
memset(&valid_until_datetime, 0x00, sizeof(valid_until_datetime));
|
||||||
|
|
||||||
|
if (!localtime_r(&valid_until_datetime_t, &valid_until_datetime)) {
|
||||||
|
return "LOCALTIME_R() ERROR";
|
||||||
|
}
|
||||||
|
|
||||||
|
// return in ISO-format: "%Y-%m-%dT%H:%M:%S"
|
||||||
char buf[128];
|
char buf[128];
|
||||||
memset(buf, 0x00, sizeof(buf));
|
memset(buf, 0x00, sizeof(buf));
|
||||||
strftime(buf, sizeof(buf)-1, "%Y-%m-%dT%H:%M:%S", &valid_until_datetime);
|
strftime(buf, sizeof(buf)-1, "%Y-%m-%dT%H:%M:%S", &valid_until_datetime);
|
||||||
|
|
||||||
// LOG_DEBUG("Ticket is valid until ", asctime(&valid_until_datetime));
|
|
||||||
LOG_DEBUG("Ticket is valid until ", buf);
|
LOG_DEBUG("Ticket is valid until ", buf);
|
||||||
|
|
||||||
total_duration_min = 0.0f;
|
total_duration_min = 0.0f;
|
||||||
|
Loading…
Reference in New Issue
Block a user