using System;
namespace StrixMusic.Helpers.TimeSpanRules
{
///
/// A rule for if day is with in a certain time range.
///
public class AnnualRangeRule : ITimeSpanRule
{
private int _startDay;
private int _endDay;
private bool _wrapped;
///
/// Initializes a new instance of the class.
///
/// The time of day to start as a DateTime.
/// The time of day to start as a DateTime.
public AnnualRangeRule(DateTime start, DateTime end)
{
_startDay = start.DayOfYear;
_endDay = end.DayOfYear;
if (_endDay < _startDay)
{
int cache = _endDay;
_endDay = _startDay;
_startDay = cache + 366;
_wrapped = true;
}
}
///
public bool IsNow(DateTime now)
{
int currentDay = now.DayOfYear;
if (_wrapped && currentDay < 366)
currentDay += 366;
return currentDay < _endDay && currentDay > _startDay;
}
}
}