Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andrew Waegel 126 posts 126 karma points
    Mar 08, 2012 @ 02:02
    Andrew Waegel
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft