/// <summary> /// usefull for comparing different periods of time. /// Often the period of time is one year. /// Modelers may model different years as scenarios. /// </summary> public static Series ShiftToYear(Series s, int year) { Series wySeries = s.Clone(); if (s.Count != 0) { int day = s[0].DateTime.Day; int month = s[0].DateTime.Month; DateTime t1; if (day == 29 && month == 2 && !DateTime.IsLeapYear(year)) { day = 28; } t1 = new DateTime(year, month, day); TimeSpan ts = new TimeSpan(t1.Ticks - s[0].DateTime.Ticks); if (s.TimeInterval == TimeInterval.Monthly) { int yearOffset = year - s[0].DateTime.Year; for (int i = 0; i < s.Count; i++) { DateTime t = s[i].DateTime; if (t.Month == 2 && t.Day == 29 && !DateTime.IsLeapYear(t.Year + yearOffset)) { t = t.AddDays(-1); } DateTime newDate = new DateTime(t.Year + yearOffset, t.Month, t.Day); wySeries.Add(newDate, s[i].Value, s[i].Flag); } } else { wySeries = Math.Shift(s, ts); } // wySeries.Table.AcceptChanges(); Series.CopyAttributes(s, wySeries); } return(wySeries); }