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
hourintHour component.
minuteintMinute component.
secondintSecond component.
millisecondintMillisecond component.
microsecondintMicrosecond component.
tickintTick 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
timeSpanis 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
otherTimeOfDayAn 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 otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin 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
objobjectAn 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 objin the sort order.Zero This instance occurs in the same position in the sort order as obj.Greater than zero This instance follows objin the sort order.
Exceptions
- ArgumentException
objis 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
otherTimeOfDayAn 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
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
valueintNew value.
Returns
Exceptions
- ArgumentOutOfRangeException
When
valueis 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
valueintNew value.
Returns
Exceptions
- ArgumentOutOfRangeException
When
valueis 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
valueintNew value.
Returns
Exceptions
- ArgumentOutOfRangeException
When
valueis 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
valueintNew value.
Returns
Exceptions
- ArgumentOutOfRangeException
When
valueis 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
valueintNew value.
Returns
Exceptions
- ArgumentOutOfRangeException
When
valueis 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
valueintNew value.
Returns
Exceptions
- ArgumentOutOfRangeException
When
valueis 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
otherTimeOfDayInstance 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
tTimeOfDayValue to convert.
Returns
explicit operator TimeSpan(TimeOfDay)
Converts the provided time of day to TimeSpan.
[Pure]
public static explicit operator TimeSpan(TimeOfDay t)
Parameters
tTimeOfDayValue 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
ais 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
ais 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
ais 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
ais 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)