public override async Task <IActionResult> GetAsync() { var asyncPatientAppointments = await base.GetAsync(); var patientAppointments = (List <PatientAppointment>)((ObjectResult)asyncPatientAppointments).Value; patientAppointments.ForEach(p => { if (!string.IsNullOrEmpty(p.RecurrenceRule)) { RecurrencePattern pattern = new RecurrencePattern(p.RecurrenceRule); pattern.RestrictionType = RecurrenceRestrictionType.NoRestriction; var us = new CultureInfo("en-US"); var startDate = new CalDateTime(p.StartDateTime, "UTC"); var fromDate = new CalDateTime(p.StartDateTime, "UTC"); var toDate = new CalDateTime(); if (pattern.Until != null && pattern.Until != DateTime.MinValue) { toDate = new CalDateTime(pattern.Until, "UTC"); } else if (pattern.Count != 0 && pattern.Count != Int32.MinValue) { toDate = new CalDateTime(p.EndDateTime.AddDays(pattern.Interval * pattern.Count), "UTC"); } else { toDate = new CalDateTime(p.EndDateTime.AddYears(2), "UTC"); } var evaluator = pattern.GetService(typeof(IEvaluator)) as IEvaluator; var tt = DateUtil.SimpleDateTimeToMatch(toDate, startDate); p.Occurrences = evaluator.Evaluate( startDate, DateUtil.SimpleDateTimeToMatch(fromDate, startDate), DateUtil.SimpleDateTimeToMatch(toDate, startDate), true) .OrderBy(o => o.StartTime) .ToList(); var endDate = new CalDateTime(p.EndDateTime, "UTC"); TimeSpan t = p.EndDateTime - p.StartDateTime; p.Occurrences.ForEach(m => m.Duration = t); p.RecurrencePattern = pattern; } }); ((ObjectResult)asyncPatientAppointments).Value = patientAppointments; return(asyncPatientAppointments); }
public void Test4() { IRecurrencePattern rpattern = new RecurrencePattern(); rpattern.ByDay.Add(new WeekDay(DayOfWeek.Saturday)); rpattern.ByDay.Add(new WeekDay(DayOfWeek.Sunday)); rpattern.Frequency = FrequencyType.Weekly; IDateTime evtStart = new iCalDateTime(2006, 12, 1); IDateTime evtEnd = new iCalDateTime(2007, 1, 1); IEvaluator evaluator = rpattern.GetService(typeof(IEvaluator)) as IEvaluator; Assert.IsNotNull(evaluator); // Add the exception dates IList<IPeriod> periods = evaluator.Evaluate( evtStart, DateUtil.GetSimpleDateTimeData(evtStart), DateUtil.SimpleDateTimeToMatch(evtEnd, evtStart), false); Assert.AreEqual(10, periods.Count); Assert.AreEqual(2, periods[0].StartTime.Day); Assert.AreEqual(3, periods[1].StartTime.Day); Assert.AreEqual(9, periods[2].StartTime.Day); Assert.AreEqual(10, periods[3].StartTime.Day); Assert.AreEqual(16, periods[4].StartTime.Day); Assert.AreEqual(17, periods[5].StartTime.Day); Assert.AreEqual(23, periods[6].StartTime.Day); Assert.AreEqual(24, periods[7].StartTime.Day); Assert.AreEqual(30, periods[8].StartTime.Day); Assert.AreEqual(31, periods[9].StartTime.Day); }
public void RecurrencePattern2() { // NOTE: evaluators are generally not meant to be used directly like this. // However, this does make a good test to ensure they behave as they should. RecurrencePattern pattern = new RecurrencePattern("FREQ=MINUTELY;INTERVAL=1"); CultureInfo us = CultureInfo.CreateSpecificCulture("en-US"); iCalDateTime startDate = new iCalDateTime(DateTime.Parse("3/31/2008 12:00:10 AM", us)); iCalDateTime fromDate = new iCalDateTime(DateTime.Parse("4/1/2008 10:08:10 AM", us)); iCalDateTime toDate = new iCalDateTime(DateTime.Parse("4/1/2008 10:43:23 AM", us)); IEvaluator evaluator = pattern.GetService(typeof(IEvaluator)) as IEvaluator; Assert.IsNotNull(evaluator); IList<IPeriod> occurrences = evaluator.Evaluate( startDate, DateUtil.SimpleDateTimeToMatch(fromDate, startDate), DateUtil.SimpleDateTimeToMatch(toDate, startDate), false); Assert.AreNotEqual(0, occurrences.Count); }
public void RecurrencePattern1() { // NOTE: evaluators are not generally meant to be used directly like this. // However, this does make a good test to ensure they behave as they should. IRecurrencePattern pattern = new RecurrencePattern("FREQ=SECONDLY;INTERVAL=10"); pattern.RestrictionType = RecurrenceRestrictionType.NoRestriction; CultureInfo us = CultureInfo.CreateSpecificCulture("en-US"); iCalDateTime startDate = new iCalDateTime(DateTime.Parse("3/30/08 11:59:40 PM", us)); iCalDateTime fromDate = new iCalDateTime(DateTime.Parse("3/30/08 11:59:40 PM", us)); iCalDateTime toDate = new iCalDateTime(DateTime.Parse("3/31/08 12:00:11 AM", us)); IEvaluator evaluator = pattern.GetService(typeof(IEvaluator)) as IEvaluator; Assert.IsNotNull(evaluator); IList<IPeriod> occurrences = evaluator.Evaluate( startDate, DateUtil.SimpleDateTimeToMatch(fromDate, startDate), DateUtil.SimpleDateTimeToMatch(toDate, startDate), false); Assert.AreEqual(4, occurrences.Count); Assert.AreEqual(new iCalDateTime(DateTime.Parse("03/30/08 11:59:40 PM", us)), occurrences[0].StartTime); Assert.AreEqual(new iCalDateTime(DateTime.Parse("03/30/08 11:59:50 PM", us)), occurrences[1].StartTime); Assert.AreEqual(new iCalDateTime(DateTime.Parse("03/31/08 12:00:00 AM", us)), occurrences[2].StartTime); Assert.AreEqual(new iCalDateTime(DateTime.Parse("03/31/08 12:00:10 AM", us)), occurrences[3].StartTime); }