Created
September 16, 2011 15:33
-
-
Save Immerseit/1222376 to your computer and use it in GitHub Desktop.
Find and fill gaps in a DateTime array
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
/// <summary> | |
/// Fill gaps in referred List (based on date). | |
/// Dynamic due to a Period which add ticks to the DateTime instead of a static "Days" or dito. | |
/// </summary> | |
public static void FillGapsInArray(ref List<ObjectWithDateField> range, Period period) | |
{ | |
long ticks = PeriodParse.GetTicks(period); | |
List<ObjectWithDateField> gaps = new List<ObjectWithDateField>(); | |
DateTime compareAt = range.First().time; | |
DateTime endAt = range.Last().time; | |
while (compareAt <= endAt) | |
{ | |
if (range.Where(d => d.time.Date == compareAt.Date).Count() < 1) | |
gaps.Add(new ObjectWithDateField() | |
{ | |
time = compareAt, | |
value = 0.00 | |
otherField = otherDummyValue, | |
}); | |
compareAt = compareAt.AddTicks(ticks); | |
} | |
range = dateRange.Concat(gaps).ToList(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment