2012-07-09 45 views
0

我的需求是每季度從一個分享點列表中獲取數據,即,我將開始日期和結束日期作爲參數,以開始日期的月份,季度要計算。我說,我通過2012年2月5日作爲我的開始日期,然後季度從二月三月開始,同樣在其餘的幾個月,獲取有關給定開始和結束日期的季度數據

現在想象我有2012年12月,2013年1月和2月包括一個季度,在我的情況下,十二月份的數據應該包括季度和1月和2月應該包括另一個季度。, 我該如何解決這個問題。

我必須顯示在我的汽車輸出名稱和一季度汽車總數 我的課程分類看起來像這樣。

public class Foo 
{ 
    public int quantity { get; set; } 
    public string cars { get; set; } 
    public DateTime date { get; set; } 
} 

List<Foo> lst = new List<Foo>(); 
lst.Add(new Foo { date = Convert.ToDateTime("31/Dec/2011"), cars = "cars1", quantity = 20 }); 
lst.Add(new Foo { date = Convert.ToDateTime("31/Dec/2011"), cars = "cars2", quantity = 30 }); 
lst.Add(new Foo { date = Convert.ToDateTime("1/Jan/2012"), cars = "cars2", quantity = 80 }); 
lst.Add(new Foo { date = Convert.ToDateTime("11/Feb/2012"), cars = "cars1", quantity = 10 }); 
lst.Add(new Foo { date = Convert.ToDateTime("29/Feb/2012"), cars = "cars3", quantity = 7 }); 
lst.Add(new Foo { date = Convert.ToDateTime("29/May/2012"), cars = "cars3", quantity = 1 }); 

回答

0

「季度」的概念是特定於域(即業務確定的),因此您需要自行實施。

class Quarter { 
    public static int GetQuarter(Datetime date){ 
     if (date >= beginningOfQuarter1 && date < endOfQuarter1){ 
      return 1; 
     } else { ... } 
    } 
} 

// elsewhere 

int someDatesQuarter = Quarter.GetQuarter(someDate); 

看看我要去哪裏?我確信有很多實現,以及那些可能更面向對象的實現。

相關問題