ScheduleWidget 2.2 Released

Tags: ScheduleWidget

First a shout out to major contributors Dajo Hein who implemented biweekly (triweekly etc.) recurring events as well as Kurt Mang  who implemented quarterly events. Not wanting to feel left out I added yearly (anniversary) events. I also took it up to .NET 4.5. You can add the nuget package to your project today.

There are a list of tutorials on the main project page to get you started. ScheduleWidget is open source and you can visit the GitHub repo here.

What's new? Let's start with biweekly events:

var aEvent = new Event()
{
    ID = 1,
    Title = "Every 2nd week on Mon",
    Frequency = 2,        // weekly
    DaysOfWeek = 2,      // every Mon
    WeeklyInterval = 2, // every 2nd week
    FirstDateTime = new DateTime(2013, 1, 1) // start date on a Tue
};

var schedule = new Schedule(aEvent);

var range = new DateRange()
{
    StartDateTime = new DateTime(2013, 1, 1),
    EndDateTime = new DateTime(2013, 6, 1)
};

var occurrences = schedule.Occurrences(range);
foreach (var date in occurrences)
{
    Console.WriteLine(date.ToShortDateString());
}

Notice two new properties of the Event class: WeeklyInterval and FirstDateTime. You still have to set the Frequency to weekly. Side note. Frequency is an enum with values:

public enum FrequencyTypeEnum
{
    None = 0,
    Daily = 1,
    Weekly = 2,
    Monthly = 4,
    Quarterly = 8,
    Yearly = 16
}

But in addition to setting the Frequency you have to set the WeeklyInterval. In the above case 2 makes the event biweekly. If you set it to 3 then it is triweekly (and so on). The FirstStartDate is required only for these types of events. Here is where you set a start date for the series of recurring events to begin.

On to quarterly events:

var aEvent = new Event()
{
    ID = 1,
    Title = "Quarterly, First Quarter, First Month, Last Week, Friday",
    Frequency = 8, // quarterly
    QuarterInterval = 1, // first quarter
    QuarterlyInterval = 1, // first month of quarter
    MonthlyInterval = 16, // last week of the month
    DaysOfWeek = 32 // Friday
};

var schedule = new Schedule(aEvent);

var range = new DateRange()
{
    StartDateTime = DateTime.Now,
    EndDateTime = DateTime.Now.AddYears(5)
};

var occurrences = schedule.Occurrences(range);
foreach (var date in occurrences)
{
    Console.WriteLine(date.ToShortDateString());
}

This can get pretty complicated. Essentially you need to think about your recurrence pattern and then build the temporal expression off of that pattern. In the above example the quarterly event recurs in the first quarter, the first month, the last week of the month on a Friday. Is that fine-grained enough? :) If I let ScheduleWidget calculate the above schedule for me I get these dates:

  • 1/31/2014
  • 1/30/2015
  • 1/29/2016
  • 1/27/2017
  • 1/26/2018

Play around with different intervals and you'll get the gist of it. Last is yearly or anniversary events:

var anniversary = new Anniversary()
{
    Day = 14,
    Month = 3
};

var aEvent = new Event()
{
    ID = 1,
    Title = "Albert Einstein's Birthday",
    Frequency = 16, // yearly
    Anniversary = anniversary
};

var schedule = new Schedule(aEvent);

var range = new DateRange()
{
    StartDateTime = DateTime.Now,
    EndDateTime = DateTime.Now.AddYears(5)
};

var occurrences = schedule.Occurrences(range);
foreach (var date in occurrences)
{
    Console.WriteLine(date.ToShortDateString());
    Console.WriteLine("Herzlichen Glückwunsch zum Geburtstag Herr Einstein!");
    Console.WriteLine("(Happy Birthday Mr. Einstein!)");
}

Here we have a new class called Anniversary which takes a day and a month. In the example above Albert Einstein's birthday is March 14. After setting the frequency to yearly I can run that out for five years and get the same date every year (3/14/2013, 3/14/2014, and so on). 

That pretty well sums it up. See all of the previous tutorials for how to create other kinds of recurring events.

8 Comments

  • Mike said

    Awesome job! One quick question: Is this new version going to be available for .net 4.0? Some projects are not going to be 4.5 for a while. Thank you.

  • Thierry said

    Hi, This is a great library - thanks for sharing it. I was wondering if there a .NET user control,user interface or jQuery UI plugin to compliment this library? Thanks and well done again. T.

  • Thierry said

    Also, is there a .net 4.0 version of this.. I guess I could grab the source from GitHub and use that. Are there any .net 4.5 specific issues in there - or do you think it is easily converted down to 4.0. Cheers.

  • pompy do brudnej wody said

    I’ll immediately grab your rss as I can not find your e-mail subscription link or newsletter service. Do you've any? Please let me know so that I could subscribe. Thanks.

  • james said

    Thierry, yes this easily compiles to .NET 4.0. No new language features are used. If I weren't so lazy I'd create two nuget packages for 4.0 and 4.5 but... well you know how it goes.

  • Chris said

    James, thank you so much for the library. I am having issue with Yearly events and am guessing that I don't have the most recent code. It looks like this is only available in 2.2, but I am unable to get the nuget package from VS 2010. It looks like the GitHub version is only 2.1? I was able to pull that down and compile but it doesn't seem to have the Yearly functionality. Thanks again! Chris

  • james said

    Chris, I need to do some work getting a fork back into the main trunk. Then I'll build two nuget packages, one for .NET 40 and another for .NET 45. It will take me some time to get to it. If you absolutely cannot wait get the code from my Anniversary Events fork and build it for .NET 40 and you're good to go. Sorry for the confusion but I've got several irons in the fire right now.

  • Hai said

    Howdy! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche. Your blog provided us beneficial information to work on. You have done a marvellous job!

Comments have been disabled for this content.