Created
February 23, 2012 19:25
-
-
Save smoak/1894497 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private struct Row | |
{ | |
public int UserId; | |
public DateTime DateUtc; | |
} | |
List<Row> table = new List<Row> | |
{ | |
new Row { UserId = 1, DateUtc = DateTime.Parse("2012-01-05 17:00:00.000") }, | |
new Row { UserId = 1, DateUtc = DateTime.Parse("2012-01-26 17:00:00.000") } | |
}; | |
var total = 0; | |
foreach (var row in table) | |
{ | |
var row1 = row; | |
foreach (var otherRow in table.Where(r => r.UserId == row1.UserId)) | |
{ | |
if (row.DateUtc.Year == otherRow.DateUtc.Year && row.DateUtc.Day == otherRow.DateUtc.Day && Math.Abs(row.DateUtc.Minute - otherRow.DateUtc.Minute) >= 60) | |
{ | |
total++; | |
} | |
if (row.DateUtc.Year == otherRow.DateUtc.Year && row.DateUtc.Day != otherRow.DateUtc.Day) | |
{ | |
total++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment