Work Calendar

Work Calendar

Released 4 years ago , Last update 4 years ago

WorkCalendar is working calendar (or business calendar) algorithm for .Net framework, give a start time and duration(such as 10 hours or 30 minutes) then it calculate the end time skip the non-working time such as saturday, sunday and holidays.

Time calculations with work hours

WorkCalendar is a work-hour calendar (or business calendar) algorithm for .Net framework, that given a start time and duration it calculate the end time - skipping the non-work time such as Saturday, Sunday and holidays.

Features

  1. Add duration to time, skip the non-work time
  2. Calculate duration, only contain work time
  3. Get nearest working time, skip the non-work time
  4. work calendar is configured in XML format

Package Contents

src -------------------------  source code contian unit test.
bin -------------------------  binary file.
doc -------------------------  document file.

How to configure work calendar

A calendar is defined in XML. A sample calendar can be found in the source code, and looks as follows:

<?xml version="1.0" encoding="UTF-8"?>
<business-calendar hoursperday="6.5">
    <monday    hours="9:00-12:00 "/>
    <tuesday   hours="9:00-12:00 and 12:30-17:00 and 19:00 - 20:00"/>
    <wednesday hours="9:00-12:00 and 12:30-17:00"/>
    <thursday  hours="9:00-12:00 and 12:30-17:00"/>
    <friday    hours="9:00-12:00 and 12:30-17:00"/>

    <workday period="2/28/2013" hours="9:00-11:00" />
    <workday period="3/2/2013" hours="9:00-12:00" />

    <holiday period="3/5/2013 - 3/7/2013"/>
    <holiday period="3/14/2013"/>
</business-calendar>

It contains the three type day: normal day, work day and holiday.

normal day element is a week day, such as Monday, Tuesday and so on, it only contains hours element, hours element contain several time span separated by and, each time span is separated by -, it can contain whitespaces before or after the char - for nice look. Take Tuesday for example, it defines every tuesday work hours from 9:00 to 12:00 in the morning and 12:30 - 17:00 in the afternoon and 19:00 to 20:00 in the evening.

workday element is used to specify the special day is a working day. such as the day is Sunday, but it is a working day for other reason. It contains period element and hours element. period element can contain only one day or a day span separated by -, for example '2/28/2013' or '3/2/2013 - 3/5/2013'. hours element is the same as normal day.

holiday element is used to specify the holiday, it only contains period element. period element is the same as workday.

How to Use

1. parse calendar xml to calendar object

string calendarFilePath = @"calendar.xml";
string calendarXml = "";
using (StreamReader sr = new StreamReader(calendarFilePath))
{
    calendarXml = sr.ReadToEnd();
    sr.Close();
}
CalendarParser parser = new CalendarParser();
ICalendar calendar = parser.Parse(calendarXml);

2. Add duration to time, it will skip the non-working time

DateTime startTime = DateTime.Now;
long seconds = 3600;
DateTime endTime = calendar.Add(startTime, seconds);

3. Calculate duration, it will only contain working time

DateTime startTime = new DateTime(2013, 1, 1, 8, 30, 0);
DateTime endTime = new DateTime(2013, 1, 5, 10, 30, 0);
long duration = calendar.CalculateDuration(startTime, endTime);

4. Get nearest working time, it will skip the non-working time

DateTime startTime = new DateTime(2013, 1, 1, 8, 0, 0);
DateTime workingTime = calendar.GetNearestWorkingTime(startTime);

Pricing

14 day 14-day money-back guarantee

$29.99

Application License

  • Perpetual license

  • 1 application

  • Can distribute binary products only

  • Commercial use

  • 6 months support

2 licenses, starting from From » $29.99 View Licenses

Get A Quote

What do you need?
  • Custom development
  • Integration
  • Customization / Reskinning
  • Consultation
When do you need it?
  • Soon
  • Next week
  • Next month
  • Anytime

Thanks for getting in touch!

Your quote details have been received and we'll get back to you soon.


Or enter your name and Email
No comments have been posted yet.