I'm making a graph that cover "1930-1940", "1940-1950", "1950-1960", "1960-1970", ...
I want to represent this with a DateTime
and a Timespan
, but I'm not really sure how to make the TimeSpan
, and I find it hard to verify if my timespans are correct.
Is this how I should use TimeSpan
, or does it overlap? If it's overlapning then how can I fix it?
List<DateTime> list1 = new List<DateTime>();
List<TimeSpan> list2 = new List<TimeSpan>();
int startYearInt = 1930;
int times = 0;
const int intervalSize = 10;
for (int i = startYearInt; i < 2020; i += intervalSize)
{
DateTime sYear = new DateTime(startYearInt + (intervalSize * times++), 1, 1);
TimeSpan period = (sYear.AddYears(intervalSize)) - sYear;
list1.Add(sYear);
list2.Add(period); // <<-- Don't know if if this is correct?
}
EDIT: I have this too. And if My timespan is too small or to last it can give some problems.
public bool IsInsidePeriod(DateTime dt)
{
return dt >= FromYearDateTime && dt < FromYearDateTime.Add(periodTimeSpan);
}
TimeSpan
is simply and amount of time, not attached to any points in time (a span of 10 years is just that - it may be a span of 10 years a century ago or a millennium hence). – Bohnerperiod
variable to see what decade it belongs to or if a specific year belongs to it. – Bohner