Version

IsInWorkingHours(TimeSlot,DateTime) Method

Returns whether the specified TimeSlot falls within working hours for the specified date.
Syntax
'Declaration
 
Public Overloads Function IsInWorkingHours( _
   ByVal timeSlot As TimeSlot, _
   ByVal date As Date _
) As Boolean
public bool IsInWorkingHours( 
   TimeSlot timeSlot,
   DateTime date
)

Parameters

timeSlot
The TimeSlot instance which defines the starting and ending times of the range to test.
date
The date to test.

Return Value

True if the TimeSlot falls within working hours, false otherwise.
Example
The following code sample demonstrates how to use the IsInWorkingHours method to determine whether a TimeSlot falls within the working hour range for a given date:

Imports System.Collections.Generic
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinSchedule
Imports System.Diagnostics


    AddHandler Me.dayView.MouseDown, AddressOf dayView_MouseDown

    Private Sub dayView_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)

        Dim dayView As UltraDayView = sender

        '  Use the OwnerFromPoint method to hit test for an Owner
        Dim ownerAtPoint As Owner = dayView.OwnerFromPoint(e.Location)

        '  Use the DateTimeFromPoint method to hit test for the date and TimeSlot
        Dim timeSlot As TimeSlot = Nothing
        Dim dateAtPoint As Nullable(Of DateTime) = dayView.DateTimeFromPoint(e.Location, timeSlot)
        Dim isInWorkingHours As Boolean = False

        If Not timeSlot Is Nothing Then

            If Not ownerAtPoint Is Nothing Then
                isInWorkingHours = ownerAtPoint.IsInWorkingHours(timeSlot, dateAtPoint.Value)
            Else

                '  Create a TimeRange from the WorkDayStartTime and WorkDayEndTime, and then
                '  use it to determine whether the TimeSlot is within that range
                Dim dayOfWeek As DayOfWeek = dayView.CalendarInfo.DaysOfWeek(dateAtPoint.Value.DayOfWeek)
                Dim TimeRange As TimeRange = New TimeRange(dayOfWeek.WorkDayStartTime.TimeOfDay, dayOfWeek.WorkDayEndTime.TimeOfDay)
                Dim intersects As Boolean = TimeRange.IsInRange(timeSlot)
                isInWorkingHours = dayOfWeek.IsWorkDay AndAlso intersects
            End If

            Dim timeSlotRange As TimeRange = TimeRange.FromTimeSlot(timeSlot, False)
            Dim notString As String = IIf(isInWorkingHours = False, "not ", String.Empty)
            Console.WriteLine(String.Format("The {0} time range is {1}within the working hour range.", timeSlotRange.ToString(True), notString))
        End If

    End Sub
using System.Collections.Generic;
using Infragistics.Win;
using Infragistics.Win.UltraWinSchedule;
using System.Diagnostics;

    this.dayView.MouseDown += new MouseEventHandler(dayView_MouseDown);

    void dayView_MouseDown(object sender, MouseEventArgs e)
    {
        UltraDayView dayView = sender as UltraDayView;
        
        //  Use the OwnerFromPoint method to hit test for an Owner
        Owner ownerAtPoint = dayView.OwnerFromPoint( e.Location );
        
        //  Use the DateTimeFromPoint method to hit test for the date and TimeSlot
        TimeSlot timeSlot = null;
        Nullable<DateTime> dateAtPoint = dayView.DateTimeFromPoint( e.Location, out timeSlot );
        bool isInWorkingHours = false;

        if ( timeSlot != null )
        {
            if ( ownerAtPoint != null )
                isInWorkingHours = ownerAtPoint.IsInWorkingHours( timeSlot, dateAtPoint.Value );
            else
            {
                //  Create a TimeRange from the WorkDayStartTime and WorkDayEndTime, and then
                //  use it to determine whether the TimeSlot is within that range
                DayOfWeek dayOfWeek = dayView.CalendarInfo.DaysOfWeek[dateAtPoint.Value.DayOfWeek];
                TimeRange timeRange = new TimeRange( dayOfWeek.WorkDayStartTime.TimeOfDay, dayOfWeek.WorkDayEndTime.TimeOfDay );
                bool intersects = timeRange.IsInRange( timeSlot );
                isInWorkingHours = dayOfWeek.IsWorkDay && intersects;
            }

            TimeRange timeSlotRange = TimeRange.FromTimeSlot( timeSlot, false );
            string notString = isInWorkingHours == false ? "not " : string.Empty;
            Console.WriteLine( string.Format("The {0} time range is {1}within the working hour range.", timeSlotRange.ToString(true), notString) );
        }

    }
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also