Work Calendar

Bookmark and Share
November 14, 2013 at 06:00AM

.NET – Work Calendar | CodeCanyon

Work Calendar his title this type of .NET/Calendars This time I will review,made by ser-html, .NET/Calendars is sold at a price of $4 in themeforest.Work Calendar - CodeCanyon Item for Salebusiness calendar // working calendar //

Created13 November 13
Last Update13 November 13
Software Version.NET 2.0, .NET 3.0, .NET 3.5, .NET 3.7, .NET 4.0, .NET 4.5
High ResolutionNo
Files IncludedC# CS
More Info…Work Calendar ..

Description

Work Calendar 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.

Features

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

Package Content

Folder

  • src ----- source code and unit test.
  • bin ----- binary file.

How to define work calendar

Calendar is define in xml, it contain the three type day: normal day, work day and holiday.Sample calendar:

  <?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>  

How to use it

  • parse calendar xml to calendar object

    string calendarFilePath = @"calendar.xml"; string calendarXml = ""; using (StreamReader sr = new StreamReader(calendarFilePath)) { calendarXml = sr.ReadToEnd(); } CalendarParser parser = new CalendarParser(); ICalendar calendar = parser.Parse(calendarXml); 
  • Add duration to time, skip the non-working time

    DateTime startTime = DateTime.Now; long seconds = 3600; DateTime endTime = calendar.Add(startTime, seconds); 
  • Calculate duration, only contain working time

    startTime = new DateTime(2013, 1, 1, 8, 30, 0); endTime = new DateTime(2013, 1, 5, 10, 30, 0); long duration = calendar.CalculateDuration(startTime, endTime); 
  • get nearest working time, skip the non-working time

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

Support

Once again, As I said at the beginning, I’d be glad to help you if you have any questions relating to this code. I’ll do my best to assist. Thanks so much!.

{ 0 comments... Views All / Send Comment! }

Post a Comment