41 lines
861 B
C++
41 lines
861 B
C++
#include <stdio.h>
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
#include "period.h"
|
|
|
|
period::period(uint16_t start, uint16_t end)
|
|
{
|
|
this->start = start;
|
|
this->end = end;
|
|
}
|
|
|
|
Json::Value
|
|
period::to_json()
|
|
{
|
|
Json::Value result;
|
|
|
|
char start_str[6], end_str[6];
|
|
|
|
sprintf(start_str, "%02d:%02d", (int)(this->start / 60), this->start % 60);
|
|
sprintf(end_str, "%02d:%02d", (int)(this->end / 60), this->end % 60);
|
|
|
|
result["start"] = std::string(start_str);
|
|
result["end"] = std::string(end_str);
|
|
|
|
return result;
|
|
}
|
|
|
|
bool
|
|
period::is_in_period(uint16_t timestamp)
|
|
{
|
|
if(this->start < this->end)
|
|
{
|
|
return this->start <= timestamp and timestamp <= this->end;
|
|
}
|
|
if(this->start > this->end)
|
|
{
|
|
return this->end <= timestamp and timestamp <= this->start;
|
|
}
|
|
return this->start == timestamp;
|
|
}
|