fix: timezone issue

This commit is contained in:
Tobias Reisinger 2020-05-07 01:41:16 +02:00
parent ad7a6028b3
commit 27cec1d8cc
10 changed files with 27 additions and 28 deletions

View file

@ -15,11 +15,14 @@ period_create(uint16_t start, uint16_t end)
}
int
period_includes_time(period_t *period, uint16_t timestamp)
period_includes_time(period_t *period, struct tm *time_struct)
{
uint16_t start = period->start;
uint16_t end = period->end;
time_t timestamp = time_struct->tm_hour * 60;
timestamp += time_struct->tm_min;
// "normal" timespan
if(start < end)
{

View file

@ -34,22 +34,17 @@ relay_set_name(relay_t *relay, const char *name)
}
int
relay_is_active(relay_t *relay, time_t timestamp_now)
relay_is_active(relay_t *relay, struct tm *time_struct)
{
schedule_t *schedule = relay->schedules[helper_get_weekday(timestamp_now)];
schedule_t *schedule = relay->schedules[helper_get_weekday(time_struct)];
if(schedule->length == 0)
{
return 0;
}
// we don't need days. reduce to hours, minutes and seconds
timestamp_now %= SECONDS_PER_DAY;
// finally remove seconds
timestamp_now /= SECONDS_PER_MINUTE;
for(uint16_t i = 0; i < schedule->length; ++i)
{
if(period_includes_time(schedule->periods[i], timestamp_now))
if(period_includes_time(schedule->periods[i], time_struct))
{
return 1;
}