From: Gerd v. Egidy Date: Thu, 29 Jan 2009 19:53:30 +0000 (+0100) Subject: found out how to reliably get the start of the day (without caring for DST), X-Git-Tag: v2.6~136^2~10 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=f60e4880eb28f8b558ac0a233a3cb9a881a31900;p=libi2ncommon found out how to reliably get the start of the day (without caring for DST), calculating the calc_from-parameter in cases where the schedule has already happened today is now unaffected by DST-changes --- diff --git a/src/cron.cpp b/src/cron.cpp index 05587cc..08d1e74 100644 --- a/src/cron.cpp +++ b/src/cron.cpp @@ -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(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(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;