From 5afa1d2819162d46cf5e836ec67a4ed4365e8068 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Wed, 4 May 2022 11:01:10 +0200 Subject: [PATCH] Use timezone as time offset for manual time When entering manual time, the timezone was adjusted in the time input instead of storing the time offset. The time offset is necessary to calculate the correct day boundaries. Remove the timezone correction of time input and instead adjust the time offset accordingly. --- main.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index 2fe07db..0fcf4fa 100644 --- a/main.c +++ b/main.c @@ -72,6 +72,13 @@ static inline void adjust_timerspec(struct itimerspec *timerspec) { } #endif +static time_t get_timezone(void) { + struct tm tm; + time_t now = time(NULL); + localtime_r(&now, &tm); + return tm.tm_gmtoff; +} + static time_t round_day_offset(time_t now, time_t offset) { return now - ((now - offset) % 86400); } @@ -115,7 +122,7 @@ struct context { struct config config; struct sun sun; - double longitude_time_offset; + time_t longitude_time_offset; enum state state; enum sun_condition condition; @@ -729,6 +736,8 @@ static int wlrun(struct config cfg) { if (!cfg.manual_time) { ctx.longitude_time_offset = longitude_time_offset(cfg.longitude); + } else { + ctx.longitude_time_offset = get_timezone(); } wl_list_init(&ctx.outputs); @@ -804,11 +813,6 @@ static int parse_time_of_day(const char *s, time_t *time) { return -1; } *time = tm.tm_hour * 3600 + tm.tm_min * 60; -#if defined(__FreeBSD__) - *time += tm.tm_gmtoff; -#else - *time += timezone; -#endif return 0; }