Struct TimeOfDay
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
intHour component.
minute
intMinute component.
second
intSecond component.
millisecond
intMillisecond component.
microsecond
intMicrosecond component.
tick
intTick component.
Exceptions
- ArgumentOutOfRangeException
When any component is not valid.
TimeOfDay(TimeSpan)
Creates a new TimeOfDay instance.
public TimeOfDay(TimeSpan timeSpan)
Parameters
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
Mid
Represents the middle of the day, that is noon, 12:00:00.0000000.
public static readonly TimeOfDay Mid
Field Value
Start
Represents the start of the day, that is midnight, 00:00:00.0000000.
public static readonly TimeOfDay Start
Field Value
Properties
Hour
Hour component.
public int Hour { get; }
Property Value
Microsecond
Microsecond component.
public int Microsecond { get; }
Property Value
Millisecond
Millisecond component.
public int Millisecond { get; }
Property Value
Minute
Minute component.
public int Minute { get; }
Property Value
Second
Second component.
public int Second { get; }
Property Value
Tick
Tick component. One tick is equivalent to 100 nanoseconds.
public int Tick { get; }
Property Value
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
TimeOfDayAn 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
objectAn 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
TimeOfDayAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
[Pure]
public override bool Equals(object? obj)
Parameters
obj
objectThe 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
SetHour(int)
Creates a new TimeOfDay instance by setting the number of hours.
[Pure]
public TimeOfDay SetHour(int value)
Parameters
value
intNew value.
Returns
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
intNew value.
Returns
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
intNew value.
Returns
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
intNew value.
Returns
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
intNew value.
Returns
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
intNew value.
Returns
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
TimeOfDayInstance to subtract.
Returns
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
TrimToMicrosecond()
Creates a new TimeOfDay instance by truncating this instance to microseconds.
[Pure]
public TimeOfDay TrimToMicrosecond()
Returns
TrimToMillisecond()
Creates a new TimeOfDay instance by truncating this instance to milliseconds.
[Pure]
public TimeOfDay TrimToMillisecond()
Returns
TrimToMinute()
Creates a new TimeOfDay instance by truncating this instance to minutes.
[Pure]
public TimeOfDay TrimToMinute()
Returns
TrimToSecond()
Creates a new TimeOfDay instance by truncating this instance to seconds.
[Pure]
public TimeOfDay TrimToSecond()
Returns
Operators
operator ==(TimeOfDay, TimeOfDay)
Checks if a
is equal to b
.
[Pure]
public static bool operator ==(TimeOfDay a, TimeOfDay b)
Parameters
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
TimeOfDayValue to convert.
Returns
explicit operator TimeSpan(TimeOfDay)
Converts the provided time of day to TimeSpan.
[Pure]
public static explicit operator TimeSpan(TimeOfDay t)
Parameters
t
TimeOfDayValue to convert.
Returns
operator >(TimeOfDay, TimeOfDay)
Checks if a
is greater than b
.
[Pure]
public static bool operator >(TimeOfDay a, TimeOfDay b)
Parameters
Returns
- bool
true when
a
is greater thanb
, 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
Returns
- bool
true when
a
is greater than or equal tob
, otherwise false.
operator !=(TimeOfDay, TimeOfDay)
Checks if a
is not equal to b
.
[Pure]
public static bool operator !=(TimeOfDay a, TimeOfDay b)
Parameters
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
Returns
- bool
true when
a
is less thanb
, 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
Returns
- bool
true when
a
is less than or equal tob
, otherwise false.
operator -(TimeOfDay, TimeOfDay)
Creates a new Duration instance by subtracting b
from a
.
[Pure]
public static Duration operator -(TimeOfDay a, TimeOfDay b)