Class DateTimeExtensions
- Namespace
- Cuemon.Extensions
- Assembly
- Cuemon.Extensions.Core.dll
Extension methods for the DateTime struct.
public static class DateTimeExtensions
- Inheritance
-
DateTimeExtensions
Methods
Ceiling(DateTime, Double, TimeUnit)
Returns a DateTime value that is rounded towards positive infinity.
public static DateTime Ceiling(this DateTime value, double interval, TimeUnit timeUnit)
Parameters
value
DateTimeThe DateTime to extend.
interval
DoubleThe Double value that in combination with
timeUnit
specifies the rounding ofvalue
.timeUnit
TimeUnitOne of the enumeration values that specifies the time unit of
interval
.
Returns
Exceptions
- ArgumentOutOfRangeException
interval
is 0.
Ceiling(DateTime, TimeSpan)
Returns a DateTime value that is rounded towards positive infinity.
public static DateTime Ceiling(this DateTime value, TimeSpan interval)
Parameters
value
DateTimeThe DateTime to extend.
interval
TimeSpanThe TimeSpan value that specifies the rounding of
value
.
Returns
Floor(DateTime, Double, TimeUnit)
Returns a DateTime value that is rounded towards negative infinity.
public static DateTime Floor(this DateTime value, double interval, TimeUnit timeUnit)
Parameters
value
DateTimeThe DateTime to extend.
interval
DoubleThe Double value that in combination with
timeUnit
specifies the rounding ofvalue
.timeUnit
TimeUnitOne of the enumeration values that specifies the time unit of
interval
.
Returns
Exceptions
- ArgumentOutOfRangeException
interval
is 0.
Floor(DateTime, TimeSpan)
Returns a DateTime value that is rounded towards negative infinity.
public static DateTime Floor(this DateTime value, TimeSpan interval)
Parameters
value
DateTimeThe DateTime to extend.
interval
TimeSpanThe TimeSpan value that specifies the rounding of
value
.
Returns
IsTimeOfDayAfternoon(DateTime)
Determines whether the specified value
is within Afternoon.
public static bool IsTimeOfDayAfternoon(this DateTime value)
Parameters
Returns
IsTimeOfDayEvening(DateTime)
Determines whether the specified value
is within Evening.
public static bool IsTimeOfDayEvening(this DateTime value)
Parameters
Returns
IsTimeOfDayForenoon(DateTime)
Determines whether the specified value
is within Forenoon.
public static bool IsTimeOfDayForenoon(this DateTime value)
Parameters
Returns
IsTimeOfDayMorning(DateTime)
Determines whether the specified value
is within Morning.
public static bool IsTimeOfDayMorning(this DateTime value)
Parameters
Returns
IsTimeOfDayNight(DateTime)
Determines whether the specified value
is within Night.
public static bool IsTimeOfDayNight(this DateTime value)
Parameters
Returns
IsWithinRange(DateTime, DateTimeRange)
Determines whether the specified value
is within range
.
public static bool IsWithinRange(this DateTime value, DateTimeRange range)
Parameters
value
DateTimeThe DateTime to extend.
range
DateTimeRangeThe DateTimeRange of
value
.
Returns
- Boolean
true
ifvalue
is within the specifiedrange
; otherwisefalse
.
IsWithinRange(DateTime, DateTime, DateTime)
Determines whether the specified value
is within range of min
and max
.
public static bool IsWithinRange(this DateTime value, DateTime min, DateTime max)
Parameters
value
DateTimeThe DateTime to extend.
min
DateTimeThe minimum value of
value
.max
DateTimeThe maximum value of
value
.
Returns
- Boolean
true
ifvalue
is within the specified range ofmin
andmax
; otherwisefalse
.
Round(DateTime, Double, TimeUnit, VerticalDirection)
Returns a DateTime value that is rounded either towards negative infinity or positive infinity.
public static DateTime Round(this DateTime value, double interval, TimeUnit timeUnit, VerticalDirection direction)
Parameters
value
DateTimeThe DateTime to extend.
interval
DoubleThe Double value that in combination with
timeUnit
specifies the rounding ofvalue
.timeUnit
TimeUnitOne of the enumeration values that specifies the time unit of
interval
.direction
VerticalDirectionOne of the enumeration values that specifies the direction of the rounding.
Returns
Exceptions
- ArgumentOutOfRangeException
direction
is an invalid enumeration value.- ArgumentOutOfRangeException
interval
is Zero.
Round(DateTime, TimeSpan, VerticalDirection)
Returns a DateTime value that is rounded either towards negative infinity or positive infinity.
public static DateTime Round(this DateTime value, TimeSpan interval, VerticalDirection direction)
Parameters
value
DateTimeThe DateTime to extend.
interval
TimeSpanThe TimeSpan value that specifies the rounding of
value
.direction
VerticalDirectionOne of the enumeration values that specifies the direction of the rounding.
Returns
Exceptions
- ArgumentOutOfRangeException
direction
is an invalid enumeration value.- ArgumentOutOfRangeException
interval
is Zero.
ToDefaultKind(DateTime)
Converts the specified value
to a representation that is not specified as either local time or UTC.
public static DateTime ToDefaultKind(this DateTime value)
Parameters
Returns
- DateTime
A new DateTime value initialized to Unspecified that has the same number of ticks as the object represented by the
value
parameter.
ToLocalKind(DateTime)
Converts the specified value
to a local time representation.
public static DateTime ToLocalKind(this DateTime value)
Parameters
Returns
- DateTime
A new DateTime value initialized to Local that has the same number of ticks as the object represented by the
value
parameter.
ToUnixEpochTime(DateTime)
Converts the specified value
to an equivalent UNIX Epoch time representation.
public static double ToUnixEpochTime(this DateTime value)
Parameters
Returns
Remarks
ToUtcKind(DateTime)
Converts the specified value
to a Coordinated Universal Time (UTC) representation.
public static DateTime ToUtcKind(this DateTime value)