UnVersion 1.4 was still not deleting for me, and it again had to do with date comparisons - the database I restored to my dev machine had version dates like this:
17/02/2012 12:14:41
...whereas DateTime.Now looked like this:
07/03/2012 15:34:10
Subtracting those and applying the '.Days' method always returned 0.
I updated the iteration to use the DateTime.Subtract method to determine the day-age of an entry, and compare that to the config:
while (reader.Read()) { var versionId = reader.GetGuid("VersionId"); var versionDate = reader.GetDateTime("VersionDate"); var published = reader.GetBoolean("published"); var newest = reader.GetBoolean("newest"); // var daysOld = (DateTime.Now - versionDate).Days; int daysOld = DateTime.Now.Subtract(versionDate).Days;
Date comparison bug (+ fix) in v1.4
Hello,
UnVersion 1.4 was still not deleting for me, and it again had to do with date comparisons - the database I restored to my dev machine had version dates like this:
17/02/2012 12:14:41
...whereas DateTime.Now looked like this:
07/03/2012 15:34:10
Subtracting those and applying the '.Days' method always returned 0.
I updated the iteration to use the DateTime.Subtract method to determine the day-age of an entry, and compare that to the config:
while (reader.Read())
{
var versionId = reader.GetGuid("VersionId");
var versionDate = reader.GetDateTime("VersionDate");
var published = reader.GetBoolean("published");
var newest = reader.GetBoolean("newest");
// var daysOld = (DateTime.Now - versionDate).Days;
int daysOld = DateTime.Now.Subtract(versionDate).Days;
readerIndex++;
if(published || newest || readerIndex <= configEntry.MaxCount || daysOld < configEntry.MaxDays)
versionsToKeep.Add("'"+ versionId.ToString("D") +"'");
}
There may be better ways to do it, but this is working for me.
- Andrew
is working on a reply...