c# - Find gaps in a List of object with Start/End dates -


i have list of objects hold start , end date rate person charged.

public class projectresourcecostdto     {         public int id { get; set; }         public int projectresourceid { get; set; }         public datetime startdate { get; set; }         public datetime? enddate { get; set; }         public decimal cost { get; set; }         public bool deleted { get; set; }     } 

i have project start , end date. need return list<> of 'gaps', there no rate set.

so, if have project start date "01-jan-2013" , end on "31-dec-2013", inputs.

i need go through list, , output list of start/end dates there no payment rates.

so, if list of objects have:

start=05-jan-2013 end=01-oct-2013

start=15-oct-2013 end=25-dec-2013

then, i'd need return: 01-jan-2013 04-jan-2013

02-oct-2013 14-oct-2013

26-dec-2013 31-dec-2013

those period can't determine rate.

it's done in c# code. i'm using entity framework, maybe option view in sql server, can make use of ... have calendar table dates... first prize if had routine use in code work out these period.

you can order list of inputs date (start date, example) , iterate through adding dates new list every time target condition met (i.e., cost = 0). here have sample code writing relevant dates gapslist:

list<projectresourcecostdto> testlist = new list<projectresourcecostdto>(); testlist.add(new projectresourcecostdto{id = 1, projectresourceid = 1, startdate = new datetime(2001,2,1), enddate = new datetime(2002, 1,1), cost = 1111, deleted = false}); testlist.add(new projectresourcecostdto{id = 2, projectresourceid = 2, startdate = new datetime(2003,1,1), enddate = new datetime(2004, 1,1), cost = 0, deleted = false}); testlist.add(new projectresourcecostdto { id = 3, projectresourceid = 3, startdate = new datetime(2005, 1, 1), enddate = new datetime(2006, 1, 1), cost = 999, deleted = false });  datetime firstdate = new datetime(2001, 1, 1); datetime lastdate = new datetime(2006, 2, 1); list<datetime> gapslist = new list<datetime>(); gapslist.add(firstdate); testlist = testlist.orderby(n => n.startdate).tolist(); foreach(projectresourcecostdto item in testlist) {     if (item.cost == 0)     {         gapslist.add(item.startdate);         gapslist.add((datetime)item.enddate);     } } gapslist.add(lastdate); 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -