Branch: Tag:

2020-03-27

2020-03-27 10:56:16 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Variable.Schedule: Fix handling of DST transition.

Fix issue where next_day() returned a time one hour into the
next day rather than at hour 0 if the transition to dst was
in the interval. This in turn caused next_or_same_time() to
skip a week ahead if the targetted time was 00:00.

Fixes [WS-606].

78:      private mapping next_day(mapping from, int day)   { -  from->hour = 0; -  if(from->wday<day) { -  return localtime(mktime(from) + (day - from->wday)*3600*24); +  int num_days = ((6 + day - from->wday) % 7) + 1; +  +  // NB: Use a time in the middle of the date to ensure that we +  // don't miss the next day due to DST or similar. +  // Adjust the hour back to 00 afterwards. +  from->hour = 12; +  mapping m = localtime(mktime(from) + num_days * 3600 * 24); +  m->hour = from->hour = 0; +  return m;   } -  return localtime(mktime(from) + (7 - from->wday + day)*3600*24); - } +       private mapping next_or_same_time(mapping from, int hour, void|int delta)   {