-
Notifications
You must be signed in to change notification settings - Fork 566
Closed
Labels
Description
if timezone is not UTC, then rollover won't happen at midnight!
the bug happens when call round_time...
function, as time_t=0 is not midnight.
case DAILY:
return round_time_and_add (t, Time (24 * 60 * 60));
fix: use localtime() to get struct tm
, manipulate it according to DailyRollingFileSchedule
. re-assign it back to Time.
static
Time
get_next_rollover_time (DailyRollingFileSchedule sch, const Time& t, bool use_gmtime = false)
{
Time result(t.sec(), 0);
struct tm time;
if (use_gmtime)
result.gmtime(&time);
else
result.localtime(&time);
time.tm_isdst = 0;
switch (sch)
{
case MONTHLY:
time.tm_mon += 1; //next month
time.tm_mday = 1; //first day
time.tm_hour = 0;
time.tm_min = 0;
time.tm_sec = 0;
break;
case WEEKLY:
time.tm_mday += (7 - time.tm_wday); //next Sunday
time.tm_hour = 0;
time.tm_min = 0;
time.tm_sec = 0;
break;
case DAILY:
time.tm_mday += 1; //next day
time.tm_hour = 0;
time.tm_min = 0;
time.tm_sec = 0;
break;
case TWICE_DAILY:
if(time.tm_hour >= 12) {
time.tm_mday += 1; //next day
time.tm_hour = 0;
}
else {
time.tm_hour = 12;
}
time.tm_min = 0;
time.tm_sec = 0;
break;
case HOURLY:
time.tm_min = 0;
time.tm_sec = 0;
break;
case MINUTELY:
time.tm_sec = 0;
break;
};
result.setTime(&time);
return result;
}