core-legacy/models/period.cc
Tobias Reisinger be84c0e4c2 fix: cleanup
2019-09-08 23:42:48 +02:00

39 lines
No EOL
809 B
C++

#include <cstdio>
#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;
char start_str[8], end_str[8];
sprintf(start_str, "%02d:%02d", this->start / 60, this->start % 60);
sprintf(end_str, "%02d:%02d", 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;
}