using System.Collections.Generic;
public static void Main()
startDate: '2018-1-01T00:00:00',
endDate: '2020-8-29T00:00:00',
startDate: '2018-1-01T00:00:00',
endDate: '2020-8-29T00:00:00',
startDate: '2018-9-01T00:00:00',
endDate: '2020-8-29T00:00:00',
List<OrgCalendarAndFiscalYears> results = GetCalendarAndFiscalYears(inputJSON);
string strResults = System.Text.Json.JsonSerializer.Serialize<List<OrgCalendarAndFiscalYears>>(results);
Console.WriteLine(strResults);
static List<OrgCalendarAndFiscalYears> GetCalendarAndFiscalYears(string inputJSON)
List<OrgInfo> orgInfo = JsonConvert.DeserializeObject<List<OrgInfo>>(inputJSON);
List<OrgCalendarAndFiscalYears> result = new List<OrgCalendarAndFiscalYears>();
foreach (OrgInfo org in orgInfo)
OrgCalendarAndFiscalYears orgCFY = new OrgCalendarAndFiscalYears();
orgCFY.OrgId = org.OrgId;
orgCFY.CalendarYears = GetCalendarYears(org);
orgCFY.FiscalYears = GetFiscalYears(org);
static List<int> GetCalendarYears(OrgInfo org)
List<int> result = new List<int>();
int years = org.EndDate.Year - org.StartDate.Year + 1;
int currentYear = org.StartDate.Year;
for (int i = 0; i < years; i++)
static List<int> GetFiscalYears(OrgInfo org)
DateTime beginDate = org.StartDate;
DateTime endDate = org.EndDate;
List<Term> terms = new List<Term>();
while (beginDate < endDate)
Term currentTerm = new Term();
currentTerm.StartDate = beginDate;
if (currentTerm.StartDate.Month == 1)
currentTerm.EndDate = currentTerm.StartDate.AddMonths(org.FiscalYearEnd);
beginDate = currentTerm.EndDate;
currentTerm.EndDate = currentTerm.StartDate.AddYears(1);
beginDate = currentTerm.EndDate;
currentTerm.StartDate = terms.Last().EndDate;
currentTerm.EndDate = currentTerm.StartDate.AddYears(1);
beginDate = currentTerm.EndDate;
List<int> result = new List<int>();
terms.ForEach(f => result.Add(f.EndDate.AddDays(-1).Year));
public int OrgId { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int FiscalYearEnd { get; set; }
public class OrgCalendarAndFiscalYears
public int OrgId { get; set; }
public List<int> CalendarYears { get; set; }
public List<int> FiscalYears { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public class ExampleClass
public int sampleId { get; set; }
public string sampleString { get; set; }