Table of Contents

Class TimeRange

Namespace
Cuemon
Assembly
Cuemon.Core.dll

Represents a period of time between two TimeSpan values.

public class TimeRange : Range<TimeSpan>, IEqualityComparer<Range<TimeSpan>>
Inheritance
TimeRange
Implements
Inherited Members

Examples

The following example demonstrates how to use to represent a range between two values.

using System;
using Cuemon; // for TimeRange

namespace MyApp.Examples;

public class TimeRangeExample
{
    public void Demonstrate()
    {
        // Define working hours (09:00 to 17:30)
        var workDay = new TimeRange(
            TimeSpan.FromHours(9),
            TimeSpan.FromHours(17.5));

        Console.WriteLine($"Start: {workDay.Start}");     // 09:00:00
        Console.WriteLine($"End: {workDay.End}");          // 17:30:00
        Console.WriteLine($"Duration: {workDay.Duration}"); // 08:30:00

        // Use inherited formatting
        Console.WriteLine(workDay.ToString("g", null));
        // Output: A duration of 00.08:30:00 between 09:00:00 and 17:30:00.

        // Create a short break range
        var lunchBreak = new TimeRange(
            TimeSpan.FromHours(12),
            TimeSpan.FromHours(13));
        Console.WriteLine(lunchBreak.Duration); // 01:00:00

}
}

Constructors

TimeRange(TimeSpan, TimeSpan)

Initializes a new instance of the TimeRange struct.

public TimeRange(TimeSpan start, TimeSpan end)

Parameters

start TimeSpan

The start of a time range.

end TimeSpan

The end of a time range.

Methods

ToString()

Returns a string that represents this instance.

public override string ToString()

Returns

string

A string that represents this instance.