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

96 lines
3.2 KiB
C
Raw Permalink Normal View History

// #pragma once
#ifndef TARIFF_UTILS_H_INCLUDED
#define TARIFF_UTILS_H_INCLUDED
#include "tariff_day_of_week.h"
#include "tariff_cfg.h"
#include "tariff_time_range.h"
#include "active_time_range.h"
#include <stdio.h>
#include <cstring>
#include <ctime>
#include <stddef.h>
#include <locale.h>
#include <iostream>
#include <math.h>
/// <summary>
/// Definition of TariffUtilities class
/// </summary>
class TariffUtils {
public:
/// <summary>
/// Validate parking ticket
/// </summary>
/// <param name="initial"></param>
/// <param name="durationMin"></param>
/// <param name="time_range"></param>
/// <param name="isSpecialDay"></param>
/// <param name="spec_day_id"></param>
/// <returns></returns>
static bool
ValidateParkingTicket(TariffConfiguration const *tariff_cfg,
time_t initial, int durationMin,
double price, TariffTimeRange time_range,
bool isSpecialDay, int spec_day_id);
/// <summary>
/// Check if time is in range between start and end of active payment hours
/// </summary>
/// <param name="tariff_cfg">Tariff configuration</param>
/// <param name="datetimeStr">Current datetime string</param>
/// <param name="isSpecialDay">Special day flag</param>
/// <param name="spec_day_id">Special day ID</param>
/// <returns>Returns if parking time range is active</returns>
static ActiveTimeRange
isParkingTimeRangeActive(TariffConfiguration *tariff_cfg,
std::string datetimeStr, bool isSpecialDay,
int spec_day_id);
/// <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 const *t);
/// <summary>
/// Identifies special day (e.g. Christmas)
/// </summary>
/// <param name="tariff_cfg">Pointer to tariff configuration data</param>
/// <param name="date">Date to be validated</param>
/// <param name="date">Reference to special day ID</param>
/// <returns>Returns if the date is a special day</returns>
static bool IsSpecialDay(TariffConfiguration const *tariff_cfg, const char *dateTimeStr, int& specialDayId);
static bool PriceForSpecialDay(TariffConfiguration const* tariff_cfg, int specialDayId, double *price);
/// <summary>
/// Date and time parse helper function
/// </summary>
/// <returns>Returns time (tm) structure</returns>
static bool DateTimeToStructTm(const char* dateTimeStr, struct tm *t);
/// <summary>
/// Date parse helper function
/// </summary>
/// <returns>Returns time (tm) structure</returns>
static bool DateToStructTm(char const* dateStr, struct tm *t);
/// <summary>
/// Time parse helper function
/// </summary>
/// <returns>Returns time (tm) structure</returns>
static bool TimeToStructTm(const char* timeStr, struct tm *t);
/// <summary>
/// Get current local time
/// </summary>
/// <returns>Returns time_t structure</returns>
static time_t GetCurrentLocalTime();
};
#endif // TARIFF_UTILS_H_INCLUDED