found out how to reliably get the start of the day (without caring for DST),
authorGerd v. Egidy <gerd.von.egidy@intra2net.com>
Thu, 29 Jan 2009 19:53:30 +0000 (20:53 +0100)
committerGerd v. Egidy <gerd.von.egidy@intra2net.com>
Thu, 29 Jan 2009 19:56:57 +0000 (20:56 +0100)
calculating the calc_from-parameter in cases where the schedule has already happened today is now
unaffected by DST-changes

src/cron.cpp

index 05587cc..08d1e74 100644 (file)
@@ -139,35 +139,22 @@ time_t WeekCron::get_next_point(const time_t calc_from, const int daysec, const
     // take care of the weekday
     ft.tm_mday+=Week.days_till_set(static_cast<Week::WeekDay>(ft.tm_wday));
 
-    // get a time which is _really_ (=undisturbed by DST) at the day we selected
-    // 1:59h is a good time for that because it is before DST-change-hours and
-    // we currently don't have bigger DST-offsets than +-1:59h today
-    // (double-DST 1949 is not relevant because we use unixtime which is 1970+)
-    ft.tm_hour=1;
-    ft.tm_min=59;
-    ft.tm_sec=0;
-
-    // one roundtrip to get tm_isdst
-    time_t target=mktime(&ft);
-    localtime_r(&target,&ft);
-
-    // now dstft.tm_isdst is set correctly for the start of the day we selected
-
-    // calculate start of the day selected
     ft.tm_hour=0;
     ft.tm_min=0;
     ft.tm_sec=0;
+    // tm_isdst means to use the dst in use at the given time
+    ft.tm_isdst=-1;
 
     // get unixtime of start of the day and add daysec
-    target=mktime(&ft)+daysec;
+    time_t target=mktime(&ft)+daysec;
 
     // todays schedule could already been through or now
     if (todaycheck && target <= calc_from)
     {
         // not today but the next matching weekday
-        localtime_r(&calc_from,&ft);
         ft.tm_mday++;
-        return get_next_point(mktime(&ft),daysec,false);
+        ft.tm_isdst=-1;
+        target=get_next_point(mktime(&ft),daysec,false);
     }
 
     return target;
@@ -192,36 +179,23 @@ time_t WeekCron::get_previousnow_point(const time_t calc_from, const int daysec,
     // take care of the weekday
     ft.tm_mday-=Week.days_since_set(static_cast<Week::WeekDay>(ft.tm_wday));
 
-    // get a time which is _really_ (=undisturbed by DST) at the day we selected
-    // 1:59h is a good time for that because it is before DST-change-hours and
-    // we currently don't have bigger DST-offsets than +-1:59h today
-    // (double-DST 1949 is not relevant because we use unixtime which is 1970+)
-    ft.tm_hour=1;
-    ft.tm_min=59;
-    ft.tm_sec=0;
-
-    // one roundtrip to get tm_isdst
-    time_t target=mktime(&ft);
-    localtime_r(&target,&ft);
-
-    // now dstft.tm_isdst is set correctly for the start of the day we selected
-
-    // calculate start of the day selected
     ft.tm_hour=0;
     ft.tm_min=0;
     ft.tm_sec=0;
+    // tm_isdst means to use the dst in use at the given time
+    ft.tm_isdst=-1;
 
     // get unixtime of start of the day and add daysec
-    target=mktime(&ft)+daysec;
+    time_t target=mktime(&ft)+daysec;
 
     // target later than we are looking for
     // target==calc_from is ok (that's why it is called lastnow...)
     if (todaycheck && target > calc_from)
     {
-        // not today but the next matching weekday
-        localtime_r(&calc_from,&ft);
+        // not today but the previous matching weekday
         ft.tm_mday--;
-        return get_previousnow_point(mktime(&ft),daysec,false);
+        ft.tm_isdst=-1;
+        target=get_previousnow_point(mktime(&ft),daysec,false);
     }
 
     return target;