Table of Contents

Struct TimeOfDay

Namespace
LfrlAnvil.Chrono
Assembly
LfrlAnvil.Chrono.dll

Represents a time of day.

public readonly struct TimeOfDay : IEquatable<TimeOfDay>, IComparable<TimeOfDay>, IComparable
Implements
Inherited Members

Constructors

TimeOfDay(int, int, int, int, int, int)

Creates a new TimeOfDay instance.

public TimeOfDay(int hour, int minute = 0, int second = 0, int millisecond = 0, int microsecond = 0, int tick = 0)

Parameters

hour int

Hour component.

minute int

Minute component.

second int

Second component.

millisecond int

Millisecond component.

microsecond int

Microsecond component.

tick int

Tick component.

Exceptions

ArgumentOutOfRangeException

When any component is not valid.

TimeOfDay(TimeSpan)

Creates a new TimeOfDay instance.

public TimeOfDay(TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

Source TimeSpan.

Exceptions

ArgumentOutOfRangeException

When the provided timeSpan is greater than or equal to 24 hours.

Fields

End

Represents the end of the day, 23:59:59.9999999.

public static readonly TimeOfDay End

Field Value

TimeOfDay

Mid

Represents the middle of the day, that is noon, 12:00:00.0000000.

public static readonly TimeOfDay Mid

Field Value

TimeOfDay

Start

Represents the start of the day, that is midnight, 00:00:00.0000000.

public static readonly TimeOfDay Start

Field Value

TimeOfDay

Properties

Hour

Hour component.

public int Hour { get; }

Property Value

int

Microsecond

Microsecond component.

public int Microsecond { get; }

Property Value

int

Millisecond

Millisecond component.

public int Millisecond { get; }

Property Value

int

Minute

Minute component.

public int Minute { get; }

Property Value

int

Second

Second component.

public int Second { get; }

Property Value

int

Tick

Tick component. One tick is equivalent to 100 nanoseconds.

public int Tick { get; }

Property Value

int

Methods

CompareTo(TimeOfDay)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

[Pure]
public int CompareTo(TimeOfDay other)

Parameters

other TimeOfDay

An object to compare with this instance.

Returns

int

A value that indicates the relative order of the objects being compared. The return value has these meanings:

Value Meaning
Less than zero This instance precedes other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in the sort order.

CompareTo(object?)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

[Pure]
public int CompareTo(object? obj)

Parameters

obj object

An object to compare with this instance.

Returns

int

A value that indicates the relative order of the objects being compared. The return value has these meanings:

Value Meaning
Less than zero This instance precedes obj in the sort order.
Zero This instance occurs in the same position in the sort order as obj.
Greater than zero This instance follows obj in the sort order.

Exceptions

ArgumentException

obj is not the same type as this instance.

Equals(TimeOfDay)

Indicates whether the current object is equal to another object of the same type.

[Pure]
public bool Equals(TimeOfDay other)

Parameters

other TimeOfDay

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

[Pure]
public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

[Pure]
public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Invert()

Creates a new TimeOfDay instance by inverting this instance, that is subtracting it from 24 hours.

[Pure]
public TimeOfDay Invert()

Returns

TimeOfDay

New TimeOfDay instance or Start when this instance is equal to Start.

SetHour(int)

Creates a new TimeOfDay instance by setting the number of hours.

[Pure]
public TimeOfDay SetHour(int value)

Parameters

value int

New value.

Returns

TimeOfDay

New TimeOfDay instance.

Exceptions

ArgumentOutOfRangeException

When value is not in a valid range.

SetMicrosecond(int)

Creates a new TimeOfDay instance by setting the number of microseconds in the millisecond component.

[Pure]
public TimeOfDay SetMicrosecond(int value)

Parameters

value int

New value.

Returns

TimeOfDay

New TimeOfDay instance.

Exceptions

ArgumentOutOfRangeException

When value is not in a valid range.

SetMillisecond(int)

Creates a new TimeOfDay instance by setting the number of milliseconds in the second component.

[Pure]
public TimeOfDay SetMillisecond(int value)

Parameters

value int

New value.

Returns

TimeOfDay

New TimeOfDay instance.

Exceptions

ArgumentOutOfRangeException

When value is not in a valid range.

SetMinute(int)

Creates a new TimeOfDay instance by setting the number of minutes in the hour component.

[Pure]
public TimeOfDay SetMinute(int value)

Parameters

value int

New value.

Returns

TimeOfDay

New TimeOfDay instance.

Exceptions

ArgumentOutOfRangeException

When value is not in a valid range.

SetSecond(int)

Creates a new TimeOfDay instance by setting the number of seconds in the minute component.

[Pure]
public TimeOfDay SetSecond(int value)

Parameters

value int

New value.

Returns

TimeOfDay

New TimeOfDay instance.

Exceptions

ArgumentOutOfRangeException

When value is not in a valid range.

SetTick(int)

Creates a new TimeOfDay instance by setting the number of ticks in the microsecond component.

[Pure]
public TimeOfDay SetTick(int value)

Parameters

value int

New value.

Returns

TimeOfDay

New TimeOfDay instance.

Exceptions

ArgumentOutOfRangeException

When value is not in a valid range.

Subtract(TimeOfDay)

Calculates a difference between this instance and the other instance, where this instance is treated as the end of the range.

[Pure]
public Duration Subtract(TimeOfDay other)

Parameters

other TimeOfDay

Instance to subtract.

Returns

Duration

New Duration instance.

ToString()

Returns a string representation of this TimeOfDay instance.

[Pure]
public override string ToString()

Returns

string

String representation.

TrimToHour()

Creates a new TimeOfDay instance by truncating this instance to hours.

[Pure]
public TimeOfDay TrimToHour()

Returns

TimeOfDay

New TimeOfDay instance.

TrimToMicrosecond()

Creates a new TimeOfDay instance by truncating this instance to microseconds.

[Pure]
public TimeOfDay TrimToMicrosecond()

Returns

TimeOfDay

New TimeOfDay instance.

TrimToMillisecond()

Creates a new TimeOfDay instance by truncating this instance to milliseconds.

[Pure]
public TimeOfDay TrimToMillisecond()

Returns

TimeOfDay

New TimeOfDay instance.

TrimToMinute()

Creates a new TimeOfDay instance by truncating this instance to minutes.

[Pure]
public TimeOfDay TrimToMinute()

Returns

TimeOfDay

New TimeOfDay instance.

TrimToSecond()

Creates a new TimeOfDay instance by truncating this instance to seconds.

[Pure]
public TimeOfDay TrimToSecond()

Returns

TimeOfDay

New TimeOfDay instance.

Operators

operator ==(TimeOfDay, TimeOfDay)

Checks if a is equal to b.

[Pure]
public static bool operator ==(TimeOfDay a, TimeOfDay b)

Parameters

a TimeOfDay

First operand.

b TimeOfDay

Second operand.

Returns

bool

true when operands are equal, otherwise false.

explicit operator Duration(TimeOfDay)

Converts the provided time of day to Duration.

[Pure]
public static explicit operator Duration(TimeOfDay t)

Parameters

t TimeOfDay

Value to convert.

Returns

Duration

New Duration instance.

explicit operator TimeSpan(TimeOfDay)

Converts the provided time of day to TimeSpan.

[Pure]
public static explicit operator TimeSpan(TimeOfDay t)

Parameters

t TimeOfDay

Value to convert.

Returns

TimeSpan

New TimeSpan instance.

operator >(TimeOfDay, TimeOfDay)

Checks if a is greater than b.

[Pure]
public static bool operator >(TimeOfDay a, TimeOfDay b)

Parameters

a TimeOfDay

First operand.

b TimeOfDay

Second operand.

Returns

bool

true when a is greater than b, otherwise false.

operator >=(TimeOfDay, TimeOfDay)

Checks if a is greater than or equal to b.

[Pure]
public static bool operator >=(TimeOfDay a, TimeOfDay b)

Parameters

a TimeOfDay

First operand.

b TimeOfDay

Second operand.

Returns

bool

true when a is greater than or equal to b, otherwise false.

operator !=(TimeOfDay, TimeOfDay)

Checks if a is not equal to b.

[Pure]
public static bool operator !=(TimeOfDay a, TimeOfDay b)

Parameters

a TimeOfDay

First operand.

b TimeOfDay

Second operand.

Returns

bool

true when operands are not equal, otherwise false.

operator <(TimeOfDay, TimeOfDay)

Checks if a is less than b.

[Pure]
public static bool operator <(TimeOfDay a, TimeOfDay b)

Parameters

a TimeOfDay

First operand.

b TimeOfDay

Second operand.

Returns

bool

true when a is less than b, otherwise false.

operator <=(TimeOfDay, TimeOfDay)

Checks if a is less than or equal to b.

[Pure]
public static bool operator <=(TimeOfDay a, TimeOfDay b)

Parameters

a TimeOfDay

First operand.

b TimeOfDay

Second operand.

Returns

bool

true when a is less than or equal to b, otherwise false.

operator -(TimeOfDay, TimeOfDay)

Creates a new Duration instance by subtracting b from a.

[Pure]
public static Duration operator -(TimeOfDay a, TimeOfDay b)

Parameters

a TimeOfDay

First operand.

b TimeOfDay

Second operand.

Returns

Duration

New Duration instance.