MOBILISIS-Calculator/library/include/mobilisis/utilities.h

73 lines
2.0 KiB
C
Raw Normal View History

#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"
using namespace std;
class Utilities {
public:
/// <summary>
/// Get day of week from current date (Zeller's Algorithm), starting day is Sunday
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
static DayOfWeek GetDayOfWeek(struct tm* tm);
/// <summary>
/// Date and time parse helper function
/// </summary>
/// <returns>Returns time (tm) structure</returns>
static struct tm DateTimeToStructTm(const char* dateTimeStr);
/// <summary>
/// Date parse helper function
/// </summary>
/// <returns>Returns time (tm) structure</returns>
static struct tm DateToStructTm(const char* dateStr);
/// <summary>
/// Time parse helper function
/// </summary>
/// <returns>Returns time (tm) structure</returns>
static 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>
static time_t GetCurrentLocalTime();
/// <summary>
/// Zeller's algorithm for determining day of week
/// </summary>
static 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>
static bool IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTime);
/// <summary>
/// Check permissions
/// </summary>
static bool CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice);
/// <summary>
/// Calculates price per unit
/// </summary>
/// <param name="pra_price"></param>
/// <returns></returns>
static double CalculatePricePerUnit(double pra_price);
};