MOBILISIS-Calculator/library/include/mobilisis/utilities.h
Gerhard Hoffmann c4cec1c04b Added overload for CheckSpecialDay().
Added helpers SpecialDaysWorkTimeFrom() and SpecialDaysWorkTimeUntil().
2023-11-26 19:51:37 +01:00

79 lines
2.3 KiB
C++

#pragma once
#include <cstring>
#include <string.h>
#include <ctime>
#include <iostream>
#include <cmath>
#include "day_of_week.h"
#include "configuration.h"
#include "time_range.h"
#include <QDateTime>
using namespace std;
namespace Utilities {
/// <summary>
/// Get day of week from current date (Zeller's Algorithm), starting day is Sunday
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
DayOfWeek GetDayOfWeek(struct tm* tm);
/// <summary>
/// Date and time parse helper function
/// </summary>
/// <returns>Returns time (tm) structure</returns>
struct tm DateTimeToStructTm(const char* dateTimeStr);
/// <summary>
/// Date parse helper function
/// </summary>
/// <returns>Returns time (tm) structure</returns>
struct tm DateToStructTm(const char* dateStr);
/// <summary>
/// Time parse helper function
/// </summary>
/// <returns>Returns time (tm) structure</returns>
struct tm TimeToStructTm(const char* timeStr, int year, int mon, int mday, int wday);
/// <summary>
/// Get current local time
/// </summary>
/// <returns>Returns time_t structure</returns>
time_t GetCurrentLocalTime();
/// <summary>
/// Zeller's algorithm for determining day of week
/// </summary>
int ZellersAlgorithm(int day, int month, int year);
/// <summary>
/// Checks if current datetime is in range between start and end month of parking worktime
/// </summary>
/// <param name="tariff_cfg"></param>
/// <param name="currentDateTime"></param>
/// <returns></returns>
bool IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTime);
/// <summary>
/// Check permissions
/// </summary>
bool CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice);
bool CheckSpecialDay(Configuration const *cfg,
QDateTime const &currentDateTimeS,
int* specialDayId, uint32_t *specialDayPrice);
/// <summary>
/// Calculates price per unit
/// </summary>
/// <param name="pra_price"></param>
/// <returns></returns>
double CalculatePricePerUnit(double pra_price, double durationUnit = -1);
QTime SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId);
QTime SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId);
}