Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bug fix for determining periodicity type.

  • Loading branch information...
commit 4fe9bb0ca2ee9d247649bf4e9cf24a6ba1ce25b9 1 parent 98a12b7
@ryanlea ryanlea authored
Showing with 16 additions and 16 deletions.
  1. +16 −16 PeriodicRollingCalendar.cs
View
32 PeriodicRollingCalendar.cs
@@ -1,10 +1,10 @@
-using System;
-using System.Data;
+using System;
+using System.Data;
namespace winsw
{
- /**
- * This is largely borrowed from the logback Rolling Calendar.
+ /**
+ * This is largely borrowed from the logback Rolling Calendar.
**/
public class PeriodicRollingCalendar
{
@@ -24,7 +24,7 @@ public PeriodicRollingCalendar(string format, long period)
public void init()
{
this._periodicityType = determinePeriodicityType();
- this._nextRoll = nextTriggeringTime(this._currentRoll);
+ this._nextRoll = nextTriggeringTime(this._currentRoll, this._period);
}
public enum PeriodicityType
@@ -32,8 +32,8 @@ public enum PeriodicityType
ERRONEOUS, TOP_OF_MILLISECOND, TOP_OF_SECOND, TOP_OF_MINUTE, TOP_OF_HOUR, TOP_OF_DAY
}
- private static PeriodicityType[] VALID_ORDERED_LIST = new PeriodicityType[] {
- PeriodicityType.TOP_OF_MILLISECOND, PeriodicityType.TOP_OF_SECOND, PeriodicityType.TOP_OF_MINUTE, PeriodicityType.TOP_OF_HOUR, PeriodicityType.TOP_OF_DAY
+ private static PeriodicityType[] VALID_ORDERED_LIST = new PeriodicityType[] {
+ PeriodicityType.TOP_OF_MILLISECOND, PeriodicityType.TOP_OF_SECOND, PeriodicityType.TOP_OF_MINUTE, PeriodicityType.TOP_OF_HOUR, PeriodicityType.TOP_OF_DAY
};
private PeriodicityType determinePeriodicityType()
@@ -46,7 +46,7 @@ private PeriodicityType determinePeriodicityType()
string r0 = epoch.ToString(_format);
periodicRollingCalendar.periodicityType = i;
- DateTime next = periodicRollingCalendar.nextTriggeringTime(epoch);
+ DateTime next = periodicRollingCalendar.nextTriggeringTime(epoch, 1);
string r1 = next.ToString(_format);
if (r0 != null && r1 != null && !r0.Equals(r1))
@@ -57,30 +57,30 @@ private PeriodicityType determinePeriodicityType()
return PeriodicityType.ERRONEOUS;
}
- private DateTime nextTriggeringTime(DateTime input)
+ private DateTime nextTriggeringTime(DateTime input, long increment)
{
DateTime output;
switch (_periodicityType)
{
case PeriodicityType.TOP_OF_MILLISECOND:
output = new DateTime(input.Year, input.Month, input.Day, input.Hour, input.Minute, input.Second, input.Millisecond);
- output = output.AddMilliseconds(_period);
+ output = output.AddMilliseconds(increment);
return output;
case PeriodicityType.TOP_OF_SECOND:
output = new DateTime(input.Year, input.Month, input.Day, input.Hour, input.Minute, input.Second);
- output = output.AddSeconds(_period);
+ output = output.AddSeconds(increment);
return output;
case PeriodicityType.TOP_OF_MINUTE:
output = new DateTime(input.Year, input.Month, input.Day, input.Hour, input.Minute, 0);
- output = output.AddMinutes(_period);
+ output = output.AddMinutes(increment);
return output;
case PeriodicityType.TOP_OF_HOUR:
output = new DateTime(input.Year, input.Month, input.Day, input.Hour, 0, 0);
- output = output.AddHours(_period);
+ output = output.AddHours(increment);
return output;
case PeriodicityType.TOP_OF_DAY:
output = new DateTime(input.Year, input.Month, input.Day);
- output = output.AddDays(_period);
+ output = output.AddDays(increment);
return output;
default:
throw new Exception("invalid periodicity type: " + _periodicityType);
@@ -103,7 +103,7 @@ public Boolean shouldRoll
if (now > this._nextRoll)
{
this._currentRoll = now;
- this._nextRoll = nextTriggeringTime(now);
+ this._nextRoll = nextTriggeringTime(now, this._period);
return true;
}
return false;
@@ -119,4 +119,4 @@ public string format
}
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.