Skip to content

Instantly share code, notes, and snippets.

@Immerseit
Created September 16, 2011 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Immerseit/1222376 to your computer and use it in GitHub Desktop.
Save Immerseit/1222376 to your computer and use it in GitHub Desktop.
Find and fill gaps in a DateTime array
/// <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