Table of Contents

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

dt DateTime

Source date time.

period Period

Period to add.

Returns

DateTime

New DateTime instance.

GetDayOfWeek(DateTime)

Gets IsoDayOfWeek from the provided dt.

[Pure]
public static IsoDayOfWeek GetDayOfWeek(this DateTime dt)

Parameters

dt DateTime

Source 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 DateTime

Source date time.

Returns

DateTime

New DateTime instance.

GetEndOfMonth(DateTime)

Gets the end of the month from the provided dt.

[Pure]
public static DateTime GetEndOfMonth(this DateTime dt)

Parameters

dt DateTime

Source date time.

Returns

DateTime

New DateTime instance.

GetEndOfWeek(DateTime, DayOfWeek)

Gets the end of the week from the provided dt.

[Pure]
public static DateTime GetEndOfWeek(this DateTime dt, DayOfWeek weekStart)

Parameters

dt DateTime

Source date time.

weekStart DayOfWeek

First day of the week.

Returns

DateTime

New DateTime instance.

GetEndOfYear(DateTime)

Gets the end of the year from the provided dt.

[Pure]
public static DateTime GetEndOfYear(this DateTime dt)

Parameters

dt DateTime

Source date time.

Returns

DateTime

New DateTime instance.

GetGreedyPeriodOffset(DateTime, DateTime, PeriodUnits)

Creates a new Period instance by calculating a difference between the provided start and endDateTime instances, using the specified units.

[Pure]
public static Period GetGreedyPeriodOffset(this DateTime end, DateTime start, PeriodUnits units)

Parameters

end DateTime

End date time.

start DateTime

Start date time.

units PeriodUnits

PeriodUnits to include in the calculated difference.

Returns

Period

New Period instance.

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 DateTime

Source 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 endDateTime instances, using the specified units.

[Pure]
public static Period GetPeriodOffset(this DateTime end, DateTime start, PeriodUnits units)

Parameters

end DateTime

End date time.

start DateTime

Start date time.

units PeriodUnits

PeriodUnits to include in the calculated difference.

Returns

Period

New Period instance.

GetStartOfDay(DateTime)

Gets the start of the day from the provided dt.

[Pure]
public static DateTime GetStartOfDay(this DateTime dt)

Parameters

dt DateTime

Source date time.

Returns

DateTime

New DateTime instance.

GetStartOfMonth(DateTime)

Gets the start of the month from the provided dt.

[Pure]
public static DateTime GetStartOfMonth(this DateTime dt)

Parameters

dt DateTime

Source date time.

Returns

DateTime

New DateTime instance.

GetStartOfWeek(DateTime, DayOfWeek)

Gets the start of the week from the provided dt.

[Pure]
public static DateTime GetStartOfWeek(this DateTime dt, DayOfWeek weekStart)

Parameters

dt DateTime

Source date time.

weekStart DayOfWeek

First day of the week.

Returns

DateTime

New DateTime instance.

GetStartOfYear(DateTime)

Gets the start of the year from the provided dt.

[Pure]
public static DateTime GetStartOfYear(this DateTime dt)

Parameters

dt DateTime

Source date time.

Returns

DateTime

New DateTime instance.

SetDayOfMonth(DateTime, int)

Creates a new DateTime instance by setting the Day of month component in the provided dt.

[Pure]
public static DateTime SetDayOfMonth(this DateTime dt, int day)

Parameters

dt DateTime

Source date time.

day int

Day of month to set.

Returns

DateTime

New DateTime instance.

Exceptions

ArgumentOutOfRangeException

When day is not valid for the current month.

SetDayOfYear(DateTime, int)

Creates a new DateTime instance by setting the DayOfYear component in the provided dt.

[Pure]
public static DateTime SetDayOfYear(this DateTime dt, int day)

Parameters

dt DateTime

Source date time.

day int

Day of year to set.

Returns

DateTime

New DateTime instance.

Exceptions

ArgumentOutOfRangeException

When day is not valid for the current year.

SetMonth(DateTime, IsoMonthOfYear)

Creates a new DateTime instance by setting the Month component in the provided dt.

[Pure]
public static DateTime SetMonth(this DateTime dt, IsoMonthOfYear month)

Parameters

dt DateTime

Source date time.

month IsoMonthOfYear

Month to set.

Returns

DateTime

New DateTime instance.

SetTimeOfDay(DateTime, TimeOfDay)

Creates a new DateTime instance by setting the TimeOfDay component in the provided dt.

[Pure]
public static DateTime SetTimeOfDay(this DateTime dt, TimeOfDay timeOfDay)

Parameters

dt DateTime

Source date time.

timeOfDay TimeOfDay

Time of day to set.

Returns

DateTime

New DateTime instance.

SetYear(DateTime, int)

Creates a new DateTime instance by setting the Year component in the provided dt.

[Pure]
public static DateTime SetYear(this DateTime dt, int year)

Parameters

dt DateTime

Source date time.

year int

Year to set.

Returns

DateTime

New DateTime instance.

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)

Parameters

dt DateTime

Source date time.

period Period

Period to subtract.

Returns

DateTime

New DateTime instance.