2020-04-13 22:50:55 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <logger.h>
|
|
|
|
#include <constants.h>
|
|
|
|
#include <models/period.h>
|
|
|
|
|
|
|
|
period_t*
|
|
|
|
period_create(uint16_t start, uint16_t end)
|
|
|
|
{
|
|
|
|
period_t *new_period = malloc(sizeof(period_t));
|
|
|
|
new_period->start = start;
|
|
|
|
new_period->end = end;
|
|
|
|
|
|
|
|
return new_period;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-05-06 23:41:16 +00:00
|
|
|
period_includes_time(period_t *period, struct tm *time_struct)
|
2020-04-13 22:50:55 +00:00
|
|
|
{
|
|
|
|
uint16_t start = period->start;
|
|
|
|
uint16_t end = period->end;
|
|
|
|
|
2020-05-06 23:41:16 +00:00
|
|
|
time_t timestamp = time_struct->tm_hour * 60;
|
|
|
|
timestamp += time_struct->tm_min;
|
|
|
|
|
2020-04-13 22:50:55 +00:00
|
|
|
// "normal" timespan
|
|
|
|
if(start < end)
|
|
|
|
{
|
|
|
|
if(start <= timestamp && end > timestamp)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// timespan goes through 00:00
|
|
|
|
if(end < start)
|
|
|
|
{
|
|
|
|
if(start >= timestamp && end < timestamp)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|