1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
| static void Main(string[] args) { var testData = new List<Stempel>() { new Stempel { WHEN = new DateTime(2018, 1, 1, 8, 0, 0), INOUT = 0 }, new Stempel { WHEN = new DateTime(2018, 1, 1, 12, 0, 0), INOUT = 1 }, new Stempel { WHEN = new DateTime(2018, 1, 1, 12, 30, 0), INOUT = 0 }, new Stempel { WHEN = new DateTime(2018, 1, 1, 17, 0, 0), INOUT = 1 }, new Stempel { WHEN = new DateTime(2018, 1, 2, 8, 0, 0), INOUT = 0 }, new Stempel { WHEN = new DateTime(2018, 1, 2, 12, 30, 0), INOUT = 1 }, new Stempel { WHEN = new DateTime(2018, 1, 2, 13, 0, 0), INOUT = 0 }, new Stempel { WHEN = new DateTime(2018, 1, 2, 17, 0, 0), INOUT = 1 }, }.OrderBy(x => x.WHEN);
var workingMinutes = testData .Where(x => x.INOUT == 0) .Select(x => testData.SkipWhile(y => y.WHEN <= x.WHEN).First(z => z.INOUT == 1).WHEN - x.WHEN) .Sum(x=> x.TotalMinutes); Console.WriteLine(workingMinutes); }
public class Stempel { public DateTime WHEN { get; set; } public int INOUT { get; set; } } |