-
Notifications
You must be signed in to change notification settings - Fork 39
/
README
67 lines (51 loc) · 2.51 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Looking for .NET Core 2.0 Version? Repo here: https://github.com/jamesstill/ScheduleWidget.Core
ScheduleWidget handles recurring events for calendars. Let's say we want to create a
recurring event for the Critical Mass Bicycle Ride, which happens in many major cities
on the last Friday of every month.
Code Sample:
// using ScheduleWidget.Enums;
// using ScheduleWidget.ScheduledEvents;
var aEvent = new Event()
{
ID = 1,
Title = "Critical Mass Bicycle Ride",
FrequencyTypeOptions = FrequencyTypeEnum.Monthly,
MonthlyIntervalOptions = MonthlyIntervalEnum.Last,
DaysOfWeekOptions = DayOfWeekEnum.Fri
};
=======
ScheduleWidget handles recurring events for calendars.
ScheduleWidget is a .NET scheduling engine that handles recurring events for calendars. I was influenced by Martin Fowler's white paper "Recurring Events for Calendars" in which he describes the broad software architecture for a recurring events scheduling engine. But I did not find any implementation of his idea in the wild. So this led me to write it myself. It's pretty easy to use ScheduleWidget. Suppose you have an event that occurs every Monday and Wednesday. Here's the code:
var aEvent = new Event()
{
ID = 1,
Title = "Every Mon and Wed",
FrequencyTypeOptions = FrequencyTypeEnum.Weekly,
DaysOfWeekOptions = DayOfWeekEnum.Mon | DayOfWeekEnum.Wed
};
var schedule = new Schedule(aEvent);
// give me all the upcoming dates for the next year
var range = new DateRange()
{
StartDateTime = DateTime.Now,
EndDateTime = DateTime.Now.AddYears(1)
};
var occurrences = schedule.Occurrences(range);
foreach(var date in occurrences)
{
System.Diagnostics.Debug.Print(date);
}
Download the ScheduleWidget Sample Project for a fully-functional test harness that
illustrates how best to use the ScheduleWidget engine. The project home page is at:
http://www.squarewidget.com/schedulewidget
=======
Now the schedule object can calculate the calendar dates for the event. Suppose I want to know if the event occurs today:
bool occursToday = schedule.IsOccurring(DateTime.Today);
Or maybe I want to get the dates for the next three months:
var range = new DateRange()
{
StartDateTime = DateTime.Today,
EndDateTime = DateTime.Today.AddMonths(3)
};
IEnumerable<DateTime> dates = schedule.Occurrences(range);
You can model one-time, daily, weekly, bi-weekly, quarterly, monthly, and yearly (anniversary) intervals. You can make exceptions for holidays. It works great with FullCalendar or any other javascript-based calendar control.