2019-07-20 12:51:45 +00:00
|
|
|
#include <cstdio>
|
2019-07-19 09:41:39 +00:00
|
|
|
#include <cstdint>
|
|
|
|
#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;
|
|
|
|
|
2019-07-30 11:25:35 +00:00
|
|
|
char start_str[8], end_str[8];
|
2019-07-19 09:41:39 +00:00
|
|
|
|
2019-07-20 12:51:45 +00:00
|
|
|
sprintf(start_str, "%02d:%02d", this->start / 60, this->start % 60);
|
|
|
|
sprintf(end_str, "%02d:%02d", this->end / 60, this->end % 60);
|
2019-07-19 09:41:39 +00:00
|
|
|
|
2019-07-19 12:42:36 +00:00
|
|
|
result["start"] = std::string(start_str);
|
|
|
|
result["end"] = std::string(end_str);
|
2019-07-19 09:41:39 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
period::is_in_period(uint16_t timestamp)
|
|
|
|
{
|
|
|
|
if(this->start < this->end)
|
|
|
|
{
|
2019-07-19 12:42:36 +00:00
|
|
|
return this->start <= timestamp and timestamp <= this->end;
|
2019-07-19 09:41:39 +00:00
|
|
|
}
|
|
|
|
if(this->start > this->end)
|
|
|
|
{
|
2019-07-19 12:42:36 +00:00
|
|
|
return this->end <= timestamp and timestamp <= this->start;
|
2019-07-19 09:41:39 +00:00
|
|
|
}
|
|
|
|
return this->start == timestamp;
|
2019-08-08 19:23:37 +00:00
|
|
|
}
|