Class DateTimeExtensions
- Namespace
- LfrlAnvil.Chrono.Extensions
- Assembly
- LfrlAnvil.Chrono.dll
Contains DateTime extension methods.
public static class DateTimeExtensions
- Inheritance
-
DateTimeExtensions
- Inherited Members
Methods
Add(DateTime, Period)
Creates a new DateTime instance by adding the provided period
to the source dt
.
[Pure]
public static DateTime Add(this DateTime dt, Period period)
Parameters
Returns
GetDayOfWeek(DateTime)
Gets IsoDayOfWeek from the provided dt
.
[Pure]
public static IsoDayOfWeek GetDayOfWeek(this DateTime dt)
Parameters
dt
DateTimeSource date time.
Returns
- IsoDayOfWeek
New IsoDayOfWeek instance.
GetEndOfDay(DateTime)
Gets the end of the day from the provided dt
.
[Pure]
public static DateTime GetEndOfDay(this DateTime dt)
Parameters
dt
DateTimeSource date time.
Returns
GetEndOfMonth(DateTime)
Gets the end of the month from the provided dt
.
[Pure]
public static DateTime GetEndOfMonth(this DateTime dt)
Parameters
dt
DateTimeSource date time.
Returns
GetEndOfWeek(DateTime, DayOfWeek)
Gets the end of the week from the provided dt
.
[Pure]
public static DateTime GetEndOfWeek(this DateTime dt, DayOfWeek weekStart)
Parameters
Returns
GetEndOfYear(DateTime)
Gets the end of the year from the provided dt
.
[Pure]
public static DateTime GetEndOfYear(this DateTime dt)
Parameters
dt
DateTimeSource date time.
Returns
GetGreedyPeriodOffset(DateTime, DateTime, PeriodUnits)
Creates a new Period instance by calculating a difference between the provided start
and end
DateTime instances, using the specified units
.
[Pure]
public static Period GetGreedyPeriodOffset(this DateTime end, DateTime start, PeriodUnits units)
Parameters
end
DateTimeEnd date time.
start
DateTimeStart date time.
units
PeriodUnitsPeriodUnits to include in the calculated difference.
Returns
Remarks
Greedy Period may contain components with negative values.
GetMonthOfYear(DateTime)
Gets IsoMonthOfYear from the provided dt
.
[Pure]
public static IsoMonthOfYear GetMonthOfYear(this DateTime dt)
Parameters
dt
DateTimeSource date time.
Returns
- IsoMonthOfYear
New IsoMonthOfYear instance.
GetPeriodOffset(DateTime, DateTime, PeriodUnits)
Creates a new Period instance by calculating a difference between the provided start
and end
DateTime instances, using the specified units
.
[Pure]
public static Period GetPeriodOffset(this DateTime end, DateTime start, PeriodUnits units)
Parameters
end
DateTimeEnd date time.
start
DateTimeStart date time.
units
PeriodUnitsPeriodUnits to include in the calculated difference.
Returns
GetStartOfDay(DateTime)
Gets the start of the day from the provided dt
.
[Pure]
public static DateTime GetStartOfDay(this DateTime dt)
Parameters
dt
DateTimeSource date time.
Returns
GetStartOfMonth(DateTime)
Gets the start of the month from the provided dt
.
[Pure]
public static DateTime GetStartOfMonth(this DateTime dt)
Parameters
dt
DateTimeSource date time.
Returns
GetStartOfWeek(DateTime, DayOfWeek)
Gets the start of the week from the provided dt
.
[Pure]
public static DateTime GetStartOfWeek(this DateTime dt, DayOfWeek weekStart)
Parameters
Returns
GetStartOfYear(DateTime)
Gets the start of the year from the provided dt
.
[Pure]
public static DateTime GetStartOfYear(this DateTime dt)
Parameters
dt
DateTimeSource date time.
Returns
SetDayOfMonth(DateTime, int)
[Pure]
public static DateTime SetDayOfMonth(this DateTime dt, int day)
Parameters
Returns
Exceptions
- ArgumentOutOfRangeException
When
day
is not valid for the current month.
SetDayOfYear(DateTime, int)
[Pure]
public static DateTime SetDayOfYear(this DateTime dt, int day)
Parameters
Returns
Exceptions
- ArgumentOutOfRangeException
When
day
is not valid for the current year.
SetMonth(DateTime, IsoMonthOfYear)
[Pure]
public static DateTime SetMonth(this DateTime dt, IsoMonthOfYear month)
Parameters
dt
DateTimeSource date time.
month
IsoMonthOfYearMonth to set.
Returns
SetTimeOfDay(DateTime, TimeOfDay)
[Pure]
public static DateTime SetTimeOfDay(this DateTime dt, TimeOfDay timeOfDay)
Parameters
Returns
SetYear(DateTime, int)
[Pure]
public static DateTime SetYear(this DateTime dt, int year)
Parameters
Returns
Exceptions
- ArgumentOutOfRangeException
When
year
is not valid.
Subtract(DateTime, Period)
Creates a new DateTime instance by subtracting the provided period
from the source dt
.
[Pure]
public static DateTime Subtract(this DateTime dt, Period period)