Chart for .NET / User's Guide / Axes / Scale / Scale Configurators / Work Calendar
In This Topic
    Work Calendar
    In This Topic

    All date/time related scales supported by the component (date time scale, value timeline scale and range timeline scale) support a feature called "Work Calendar", that allows you to skip date/time ranges from the scale. This is commonly used in financial and project management applications, where non working days and hours are not plotted. The skipped ranges are defined as rules that can be combined to define the final calendar, that consist of working days and working hours only.

    The following code examples use the NRangeTimelineScaleConfigurator, but the code is also applicable to NValueTimelineScaleConfigurator and NDateTimeScaleConfigurator. Collectively these three configurators are called date/time scale configurators in this topic.

     Enabling the Work Calendar

    You enable the work calendar on a date/time scale configurator by setting the EnableCalendar property to true:

    C#
    Copy Code

    NRangeTimelineScaleConfigurator rangeScale = new NRangeTimelineScaleConfigurator();
    rangeScale.EnableCalendar =
    true;

    Visual Basic
    Copy Code

    Dim rangeScale As New NRangeTimelineScaleConfigurator
    rangeScale.EnableCalendar =
    True

    Now the scale is configured to use the calendar settings and you can start to define rules.

     Calendar Rules

    The work calendar is defined by a set of rules, where each rule defines whether an individual day is working or non working. In addition each rule defines the time schedule (e.g. working and non working hours) within a working day. Rules stack on each other meaning that if for example the first rule defines that a particular day is a working day - say 1, March, 2010 and the second rules says its non working it will be treated as non working day. In other words subsequent rules may redefine whether a day is working or non working and to set a different schedule in case it is treated as working.

    All rules inherit from the base abstract class NCalendarRule. This class has two properties - Range and Schedule. The Range property exposes a NDateTimeRange object that limits the effect of the rule only to dates contained within this range. By default the range is initialized to cover the whole range of possible dates, but you may decide to alter this for some rules. This is most commonly used when you want to define exceptions from the general rules that apply for all dates. The following code snippet for example sets Monday and Tusday as working days for the first week of December, 2009:

     

    C#
    Copy Code

    ' create a timeline scale
    Dim rangeScale As New NRangeTimelineScaleConfigurator
    rangeScale.EnableCalendar =
    True

    ' create a week rule
    Dim wdr As New NWeekDayRule
    wdr.WeekDays = WeekDayBit.None
    wdr.Monday =
    True
    wdr.Tuesday = True
    wdr.Range = New NDateTimeRange(New DateTime(2009, 12, 7, 0, 0, 0), New DateTime(2009, 12, 14, 0, 0, 0))

    ' add rule to the calendar
    rangeScale.Calendar.Rules.Add(wdr)

    Visual Basic
    Copy Code

    ' create a timeline scale
    Dim rangeScale As New NRangeTimelineScaleConfigurator
    rangeScale.EnableCalendar =
    True

    ' create a week rule
    Dim wdr As New NWeekDayRule
    wdr.WeekDays = WeekDayBit.None
    wdr.Monday =
    True
    wdr.Tuesday = True
    wdr.Range = New NDateTimeRange(New DateTime(2009, 12, 7, 0, 0, 0), New DateTime(2009, 12, 14, 0, 0, 0))

    ' add rule to the calendar
    rangeScale.Calendar.Rules.Add(wdr)

    Week Day Rule 

    The week day rule is represented by the NWeekDayRule class and is used to define a working pattern that repeats each week. By default the week day rule treats all days as working, but you can alter that per week day - the following example shows how to set Saturday and Sunday as non working days:

    C#
    Copy Code

    NWeekDayRule wdr = new NWeekDayRule();
    wdr.Saturday =
    false;
    wdr.Sunday =
    false;

    Visual Basic
    Copy Code

    Dim wdr As New NWeekDayRule
    wdr.Saturday =
    False
    wdr.Sunday = False

    Month Day Rule

    The month day rule is represented by the NMonthDayRule class and allows you to specify that a certain day of the month is working or non working. By default this rule will apply to all months (January to December), but you can turn off some months in a manner similar to the week day rule. For example:

    C#
    Copy Code

    NMonthDayRule mdr = new NMonthDayRule();
    mdr.Months =
    MonthBit.None;
    mdr.January =
    true;
    mdr.Day = 1;
    mdr.Working =
    false;

    Visual Basic
    Copy Code

    Dim mdr As New NMonthDayRule
    mdr.Months = MonthBit.None
    mdr.January =
    True
    mdr.Day = 1
    mdr.Working =
    False

    defines the first day of January as non working.

    Range Rule

    The third rule you can use is the range rule which simply sets a specified date range as working on non working. It is represented by the NDateTimeRangeRule class:

    C#
    Copy Code

    NDateTimeRangeRule rangeRule = new NDateTimeRangeRule();
    rangeRule.Range =
    new NDateTimeRange(new DateTime(2010, 1, 1, 0, 0, 0), new DateTime(2010, 1, 31, 0, 0, 0));
    rangeRule.Working =
    false;

    Visual Basic
    Copy Code

    NDateTimeRangeRule rangeRule = new NDateTimeRangeRule();
    rangeRule.Range =
    new NDateTimeRange(new DateTime(2010, 1, 1, 0, 0, 0), new DateTime(2010, 1, 31, 0, 0, 0));
    rangeRule.Working =
    false;

     Daily Schedule

    As mentioned above each rule contains a property called Schedule that defines the working and non working hours within a working day. When a rule generates a working day it also defines it's daily working schedule. This also means that if you have two rules that define that a particular day is working the latter will define its daily schedule.

    By default all rules contain a daily schedule that does not contain a working intervals. The following code snippet shows how to define a typical 8 hours a day working week rule (9AM - 6PM):

    C#
    Copy Code

    NWeekDayRule wdr = new NWeekDayRule();
    wdr.Saturday =
    false;
    wdr.Sunday =
    false;
    wdr.Schedule.SetHourRange(0, 9,
    true);
    wdr.Schedule.SetHourRange(12, 13,
    true);
    wdr.Schedule.SetHourRange(18, 24,
    true);

    Visual Basic
    Copy Code

    Dim wdr As New NWeekDayRule
    wdr.Saturday =
    False
    wdr.Sunday = False
    wdr.Schedule.SetHourRange(0, 9, True)
    wdr.Schedule.SetHourRange(12, 13,
    True)
    wdr.Schedule.SetHourRange(18, 24,
    True)

     

     Related Examples
    Windows Forms \ Axes \ Scaling \ Date Time Work Calendar
    See Also