Skip to content

Commit ed69d69

Browse files
committed
fix calculation of daily reconnect time at DST change
1 parent 1026406 commit ed69d69

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/time.c

+7-10
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,25 @@ dhcp_time_t time_get_margin(dhcp_time_t a, dhcp_time_t b,
5555
}
5656

5757
static time_t get_hhmm(struct tm const *base_tm, unsigned int hhmm,
58-
time_t offset)
58+
unsigned int offset_days)
5959
{
6060
struct tm tm = {
6161
.tm_mday = base_tm->tm_mday,
6262
.tm_mon = base_tm->tm_mon,
6363
.tm_year = base_tm->tm_year,
64-
.tm_hour = offset == 0 ? hhmm / 100 : 0,
65-
.tm_min = offset == 0 ? hhmm % 100 : 0,
64+
.tm_hour = hhmm / 100,
65+
.tm_min = hhmm % 100,
6666
.tm_isdst = -1,
6767
};
6868

6969
time_t t;
7070

7171
t = mktime(&tm);
72-
if (offset == 0)
72+
if (offset_days == 0)
7373
return t;
7474

75-
t += offset;
76-
localtime_r(&t, &tm);
77-
78-
tm.tm_hour = hhmm / 100;
79-
tm.tm_min = hhmm % 100;
75+
tm.tm_mday += offset_days;
76+
tm.tm_isdst = -1;
8077

8178
return mktime(&tm);
8279
}
@@ -98,7 +95,7 @@ uint32_t time_max_lt(time_t now, int daily_renew)
9895

9996
renew_tm = get_hhmm(&tm, daily_renew, 0);
10097
if (renew_tm < now)
101-
renew_tm = get_hhmm(&tm, daily_renew, 24 * 3600);
98+
renew_tm = get_hhmm(&tm, daily_renew, 1);
10299

103100
if (renew_tm < now) {
104101
pr_warn("failed to find renew time");

0 commit comments

Comments
 (0)