Fixed trimming retention period interpretation.

When the retention period was set to 0, the events would not be deleted until after 1 day.
This has been fixed by taking the last hour of the current day and subtracting the retention period from that value, and then doing an "inclusive less than" check.
This commit is contained in:
Sipke Schoorstra
2014-07-12 22:46:59 -07:00
parent 98153eb25c
commit 5f61ebeee5
2 changed files with 11 additions and 4 deletions

View File

@@ -6,8 +6,11 @@ namespace Orchard.AuditTrail.Helpers {
if (value == null)
return null;
var v = value.Value;
return new DateTime(v.Year, v.Month, v.Day, 0, 0, 0, 0, v.Kind);
return Earliest(value.Value);
}
public static DateTime Earliest(this DateTime value) {
return new DateTime(value.Year, value.Month, value.Day, 0, 0, 0, 0, value.Kind);
}
public static DateTime? Latest(this DateTime? value) {
@@ -17,5 +20,9 @@ namespace Orchard.AuditTrail.Helpers {
var v = value.Value;
return new DateTime(v.Year, v.Month, v.Day, 23, 59, 59, 999, v.Kind);
}
public static DateTime Latest(this DateTime value) {
return new DateTime(value.Year, value.Month, value.Day, 23, 59, 59, 999, value.Kind);
}
}
}

View File

@@ -207,8 +207,8 @@ namespace Orchard.AuditTrail.Services {
}
public IEnumerable<AuditTrailEventRecord> Trim(TimeSpan retentionPeriod) {
var dateThreshold = _clock.UtcNow.Date - retentionPeriod;
var query = _auditTrailRepository.Table.Where(x => x.CreatedUtc < dateThreshold);
var dateThreshold = (_clock.UtcNow.Latest() - retentionPeriod);
var query = _auditTrailRepository.Table.Where(x => x.CreatedUtc <= dateThreshold);
var records = query.ToArray();
foreach (var record in records) {