Table of Contents

TimeRange Class

Definition

Namespace
Cuemon
Assemblies
Cuemon.Kernel.dll
Source
src/Cuemon.Kernel/TimeRange.cs

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.

// Program.cs
using System;
using System.Globalization;
using Cuemon; // for TimeRange

// 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", CultureInfo.InvariantCulture));
// Output: A duration of 00.08:30:00 between 9: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

Name Description
TimeRange(TimeSpan, TimeSpan, Func<TimeSpan>)

Initializes a new instance of the TimeRange struct.

Methods

Name Description
ToString()

Returns a string that represents this instance.