获取有关给定开始和结束日期的季度数据
问题描述:
我的需求是每季度从一个分享点列表中获取数据,即,我将开始日期和结束日期作为参数,以开始日期的月份,季度要计算。我说,我通过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 });
答
“季度”的概念是特定于域(即业务确定的),因此您需要自行实施。
class Quarter {
public static int GetQuarter(Datetime date){
if (date >= beginningOfQuarter1 && date < endOfQuarter1){
return 1;
} else { ... }
}
}
// elsewhere
int someDatesQuarter = Quarter.GetQuarter(someDate);
看看我要去哪里?我确信有很多实现,以及那些可能更面向对象的实现。