public static HashSet <Occurrence> GetOccurrences(IRecurrable recurrable, IDateTime periodStart, IDateTime periodEnd, bool includeReferenceDateInResults) { var evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator; if (evaluator == null || recurrable.Start == null) { return(new HashSet <Occurrence>()); } // Ensure the start time is associated with the object being queried var start = recurrable.Start; start.AssociatedObject = recurrable as ICalendarObject; // Change the time zone of periodStart/periodEnd as needed // so they can be used during the evaluation process. periodStart.TzId = start.TzId; periodEnd.TzId = start.TzId; var periods = evaluator.Evaluate(start, DateUtil.GetSimpleDateTimeData(periodStart), DateUtil.GetSimpleDateTimeData(periodEnd), includeReferenceDateInResults); var otherOccurrences = from p in periods let endTime = p.EndTime ?? p.StartTime where endTime.GreaterThan(periodStart) && p.StartTime.LessThanOrEqual(periodEnd) select new Occurrence(recurrable, p); var occurrences = new HashSet <Occurrence>(otherOccurrences); return(occurrences); }
static public IList <Occurrence> GetOccurrences(IRecurrable recurrable, IDateTime periodStart, IDateTime periodEnd, bool includeReferenceDateInResults) { List <Occurrence> occurrences = new List <Occurrence>(); IEvaluator evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator; if (evaluator != null) { // Change the time zone of periodStart/periodEnd as needed // so they can be used during the evaluation process. periodStart = DateUtil.MatchTimeZone(recurrable.Start, periodStart); periodEnd = DateUtil.MatchTimeZone(recurrable.Start, periodEnd); IList <IPeriod> periods = evaluator.Evaluate( recurrable.Start, DateUtil.GetSimpleDateTimeData(periodStart), DateUtil.GetSimpleDateTimeData(periodEnd), includeReferenceDateInResults); foreach (IPeriod p in periods) { // Filter the resulting periods to only contain those between // startTime and endTime. if (p.StartTime.GreaterThanOrEqual(periodStart) && p.StartTime.LessThanOrEqual(periodEnd)) { occurrences.Add(new Occurrence(recurrable, p)); } } occurrences.Sort(); } return(occurrences); }
/// <summary> /// Gets the occurrences. /// </summary> /// <param name="recurrable">The recurrable.</param> /// <param name="periodStart">The period start.</param> /// <param name="periodEnd">The period end.</param> /// <param name="includeReferenceDateInResults"> /// if set to <c>true</c> [include reference date in results]. /// </param> /// <returns></returns> public static IList <Occurrence> GetOccurrences(IRecurrable recurrable, IDateTime periodStart, IDateTime periodEnd, bool includeReferenceDateInResults) { var occurrences = new List <Occurrence>( ); var evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator; if (evaluator != null) { // Ensure the start time is associated with the object being queried var start = recurrable.Start.Copy <IDateTime>( ); start.AssociatedObject = recurrable as ICalendarObject; // Change the time zone of periodStart/periodEnd as needed // so they can be used during the evaluation process. periodStart = DateUtil.MatchTimeZone(start, periodStart); periodEnd = DateUtil.MatchTimeZone(start, periodEnd); ISet <IPeriod> periods = evaluator.Evaluate( start, DateUtil.GetSimpleDateTimeData(periodStart), DateUtil.GetSimpleDateTimeData(periodEnd), includeReferenceDateInResults); // Filter the resulting periods to only contain those // that occur sometime between startTime and endTime. // NOTE: fixes bug #3007244 - GetOccurences not returning long spanning all-day events occurrences.AddRange(from p in periods let endTime = p.EndTime ?? p.StartTime where endTime.GreaterThan(periodStart) && p.StartTime.LessThanOrEqual(periodEnd) select new Occurrence(recurrable, p)); occurrences.Sort( ); } return(occurrences); }
static public IList<Occurrence> GetOccurrences(IRecurrable recurrable, IDateTime periodStart, IDateTime periodEnd, bool includeReferenceDateInResults) { List<Occurrence> occurrences = new List<Occurrence>(); IEvaluator evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator; if (evaluator != null) { // Change the time zone of periodStart/periodEnd as needed // so they can be used during the evaluation process. periodStart = DateUtil.MatchTimeZone(recurrable.Start, periodStart); periodEnd = DateUtil.MatchTimeZone(recurrable.Start, periodEnd); IList<IPeriod> periods = evaluator.Evaluate( recurrable.Start, DateUtil.GetSimpleDateTimeData(periodStart), DateUtil.GetSimpleDateTimeData(periodEnd), includeReferenceDateInResults); foreach (IPeriod p in periods) { // Filter the resulting periods to only contain those // that occur sometime between startTime and endTime. // NOTE: fixes bug #3007244 - GetOccurences not returning long spanning all-day events IDateTime endTime = p.EndTime ?? p.StartTime; if (endTime.GreaterThan(periodStart) && p.StartTime.LessThanOrEqual(periodEnd)) occurrences.Add(new Occurrence(recurrable, p)); } occurrences.Sort(); } return occurrences; }
/// <summary> /// Initializes a new instance of the <see cref="RecurringEvaluator" /> class. /// </summary> /// <param name="obj">The obj.</param> public RecurringEvaluator(IRecurrable obj) { Recurrable = obj; // We're not sure if the object is a calendar object // or a calendar data type, so we need to assign // the associated object manually var calendarObject = obj as ICalendarObject; if (calendarObject != null) { // ReSharper disable DoNotCallOverridableMethodsInConstructor AssociatedObject = calendarObject; // ReSharper restore DoNotCallOverridableMethodsInConstructor } // ReSharper disable SuspiciousTypeConversion.Global var calendarDataType = obj as ICalendarDataType; // ReSharper restore SuspiciousTypeConversion.Global if (calendarDataType != null) { ICalendarDataType dt = calendarDataType; // ReSharper disable DoNotCallOverridableMethodsInConstructor AssociatedObject = dt.AssociatedObject; // ReSharper restore DoNotCallOverridableMethodsInConstructor } }
static public IList<Occurrence> GetOccurrences(IRecurrable recurrable, IDateTime dt, bool includeReferenceDateInResults) { return GetOccurrences( recurrable, new iCalDateTime(dt.Local.Date), new iCalDateTime(dt.Local.Date.AddDays(1).AddSeconds(-1)), includeReferenceDateInResults); }
static public IList <Occurrence> GetOccurrences(IRecurrable recurrable, IDateTime dt, bool includeReferenceDateInResults) { return(GetOccurrences( recurrable, new iCalDateTime(dt.Local.Date), new iCalDateTime(dt.Local.Date.AddDays(1).AddSeconds(-1)), includeReferenceDateInResults)); }
static public void ClearEvaluation(IRecurrable recurrable) { IEvaluator evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator; if (evaluator != null) { evaluator.Clear(); } }
public RecurringEvaluator(IRecurrable obj) { Recurrable = obj; // We're not sure if the object is a calendar object // or a calendar data type, so we need to assign // the associated object manually if (obj is ICalendarObject) AssociatedObject = (ICalendarObject)obj; if (obj is ICalendarDataType) { ICalendarDataType dt = (ICalendarDataType)obj; AssociatedObject = dt.AssociatedObject; } }
public RecurringEvaluator(IRecurrable obj) { Recurrable = obj; // We're not sure if the object is a calendar object // or a calendar data type, so we need to assign // the associated object manually if (obj is ICalendarObject) { AssociatedObject = (ICalendarObject)obj; } if (obj is ICalendarDataType) { var dt = (ICalendarDataType)obj; AssociatedObject = dt.AssociatedObject; } }
public static void ClearEvaluation(IRecurrable recurrable) { var evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator; evaluator?.Clear(); }
public Occurrence(IRecurrable recurrable, Period period) { Source = recurrable; Period = period; }
public Occurrence(Occurrence ao) { Period = ao.Period; Source = ao.Source; }
public TimeZoneInfoEvaluator(IRecurrable tzi) : base(tzi) { }
public Occurrence(IRecurrable recurrable, IPeriod period) { m_Source = recurrable; m_Period = period; }
public Occurrence(Occurrence ao) { m_Period = ao.Period; m_Source = ao.Source; }
public static HashSet <Occurrence> GetOccurrences(IRecurrable recurrable, IDateTime dt, bool includeReferenceDateInResults) => GetOccurrences(recurrable, new CalDateTime(dt.AsSystemLocal.Date), new CalDateTime(dt.AsSystemLocal.Date.AddDays(1).AddSeconds(-1)), includeReferenceDateInResults);
/// <summary> /// Initializes a new instance of the <see cref="Occurrence" /> structure. /// </summary> /// <param name="recurrable">The recurrable.</param> /// <param name="period">The period.</param> public Occurrence(IRecurrable recurrable, IPeriod period) { _source = recurrable; _period = period; }
private static DayOfWeek DayOfWeekFromEvent(IRecurrable ev) { var rule = ev.RecurrenceRules.SingleOrDefault(r => r.Frequency == FrequencyType.Weekly); return(rule?.ByDay[0].DayOfWeek ?? ev.Start.DayOfWeek); }
static public void ClearEvaluation(IRecurrable recurrable) { IEvaluator evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator; if (evaluator != null) evaluator.Clear(); }
/// <summary> /// Initializes a new instance of the <see cref="Occurrence" /> structure. /// </summary> /// <param name="ao">The occurrence.</param> public Occurrence(Occurrence ao) { _period = ao.Period; _source = ao.Source; }