Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculating which recurring events happen in a date rang
Message
From
18/06/2010 17:42:49
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
General information
Forum:
ASP.NET
Category:
LINQ
Miscellaneous
Thread ID:
01469538
Message ID:
01469684
Views:
41
>>>I was going to do some ugly processing with loops, but I figured maybe Linq could help me out.
>>>
>>>RecurringEvents
>>>ID (PK)
>>>StartDate (datetime)
>>>RecurrenceDays (int)
>>>
>>>How can I calculate which of these recurring events happen within a specified date range. Linq's gotta have some sexy method that will do this easily...
>>
>>Linq would surely have nice ways to have it but your layout seems very inadequate to me. For example what does RecurrenceDays stand for? Assuming it is the days that the event would be available continously from start:
>>
>>
var evList = from e in events
>>  where e.StartDate <= end && e.StartDate.AddDays( e.RecurrenceDays ) >= start
>>  select e;
>>
>>In method syntax:
>>
>>
var evList = events.Where( e => e.StartDate <= end && e.StartDate.AddDays( e.RecurrenceDays ) >= start);
>>
>>PS: You could also create extension methods in your say "ScheduleExtensions" namespace and simply use those methods for selection. It then might look like (assuming you created WithIn extension method for RecurringEvent that takes start, end parameters):
>>
>>
var evList = events.Where( e => e.WithIn( start, end ));
>>
>>Is there a setting somewhere to say that this is C# code and not VFP? Maybe class attribute or another tag?
>>Cetin
>
>I think RecurrenceDays indicates the number of days between occurences. So an event might occur, say, every 20 days. Then the requirement is not to find whether the *first* occurence falls between the start and end date but *any* occurrence (ie 20,40,60,80 days etc...)

Yeah that is another guess and you were right:) What I meant is that a recurring schedule have different components that you cannot define with just a starttime and recurrencedays (as 20,40 ... ). For example RFC 2445 and RFC 5445 define icalendar and it has a rather complicated way of defining events. An event may be recurring with different patterns between 2 given dates and also may include exceptions etc. Here is visual representation of iCalendar:

http://en.wikipedia.org/wiki/File:ICalendarSpecification.png

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform