【发布时间】:2014-12-15 02:39:48
【问题描述】:
我需要能够定义不同的年龄组,即 10 - 11、12 - 13 岁等。
我如何代表一个 AgeGroup 类,以便该年龄可以将今天、明天和将来的人适当地分组在一起,即今天的 11 岁可能明天 12 岁(在这种情况下,他将被分组到 12-13组而不是昨天的 10-11 岁组)。
到目前为止,我有这个:
public class AgeGroup
{
public string Name { get; protected set; }
public DateRange BirthDateRange { get; protected set; }
public Guid Id { get; protected set; }
public Status Status { get; protected set; }
public virtual DateRange ApplicableDateRange { get; set; }
public AgeGroup(Guid id, string name, DateRange birthDateRange,DateRange applicableDateRange)
{
Id = id;
Name = name;
Status = status;
BirthDateRange = birthDateRange;
ApplicableDateRange = applicableDateRange;
}
}
public class DateRange
{
public DateRange(DateTime startDate, DateTime endDate)
{
StartDate = startDate;
EndDate = endDate;
}
DateTime _startDate;
DateTime _endDate;
public virtual DateTime StartDate
{
get { return _startDate; }
set { _startDate = value.ToUniversalTime(); }
}
public virtual DateTime EndDate
{
get { return _endDate; }
set { _endDate = value.ToUniversalTime(); }
}
}
这个类定义了这个年龄组适用的时间范围。当适用的日期范围过去时,我们需要及时转移所有内容。但是有没有更好的方法来做到这一点?
【问题讨论】: