C# Class FluentDateTime.DateTimeExtensions

Static class containing Fluent DateTime extension methods.
Datei anzeigen Open project: FluentDateTime/FluentDateTime

Public Methods

Method Description
AddBusinessDays ( this current, int days ) : System.DateTime

Adds the given number of business days to the DateTime.

At ( this current, int hour, int minute ) : System.DateTime

Returns the given DateTime with hour and minutes set At given values.

At ( this current, int hour, int minute, int second ) : System.DateTime

Returns the given DateTime with hour and minutes and seconds set At given values.

At ( this current, int hour, int minute, int second, int milliseconds ) : System.DateTime

Returns the given DateTime with hour and minutes and seconds and milliseconds set At given values.

BeginningOfDay ( this date ) : System.DateTime

Returns the Start of the given day (the first millisecond of the given DateTime).

BeginningOfDay ( this date, int timezoneOffset ) : System.DateTime

Returns the timezone-adjusted Start of the given day (the first millisecond of the given DateTime).

DecreaseTime ( this startDate, System.TimeSpan toSubtract ) : System.DateTime

Decreases the DateTime object with given TimeSpan value.

EndOfDay ( this date ) : System.DateTime

Returns the very end of the given day (the last millisecond of the last hour for the given DateTime).

EndOfDay ( this date, int timeZoneOffset ) : System.DateTime

Returns the timezone-adjusted very end of the given day (the last millisecond of the last hour for the given DateTime).

FirstDayOfMonth ( this current ) : System.DateTime

Sets the day of the DateTime to the first day in that month.

FirstDayOfQuarter ( this current ) : System.DateTime

Sets the day of the DateTime to the first day in that calendar quarter. credit to http://www.devcurry.com/2009/05/find-first-and-last-day-of-current.html

FirstDayOfWeek ( this dateTime ) : System.DateTime

Returns a DateTime adjusted to the beginning of the week.

the beginning of the week is controlled by the current Culture

FirstDayOfYear ( this current ) : System.DateTime

Returns the first day of the year keeping the time component intact. Eg, 2011-02-04T06:40:20.005 => 2011-01-01T06:40:20.005

IncreaseTime ( this startDate, System.TimeSpan toAdd ) : System.DateTime

Increases the DateTime object with given TimeSpan value.

IsAfter ( this current, System.DateTime toCompareWith ) : bool

Determines whether the specified DateTime value is After then current value.

IsBefore ( this current, System.DateTime toCompareWith ) : bool

Determines whether the specified DateTime is before then current value.

IsInFuture ( this dateTime ) : bool

Determine if a DateTime is in the future.

IsInPast ( this dateTime ) : bool

Determine if a DateTime is in the past.

LastDayOfMonth ( this current ) : System.DateTime

Sets the day of the DateTime to the last day in that month.

LastDayOfQuarter ( this current ) : System.DateTime

Sets the day of the DateTime to the last day in that calendar quarter. credit to http://www.devcurry.com/2009/05/find-first-and-last-day-of-current.html

LastDayOfWeek ( this current ) : System.DateTime

Returns the last day of the week keeping the time component intact. Eg, 2011-12-24T06:40:20.005 => 2011-12-25T06:40:20.005

LastDayOfYear ( this current ) : System.DateTime

Returns the last day of the year keeping the time component intact. Eg, 2011-12-24T06:40:20.005 => 2011-12-31T06:40:20.005

Midnight ( this value ) : System.DateTime

Returns original DateTime value with time part set to midnight (alias for BeginningOfDay method).

Next ( this start, DayOfWeek day ) : System.DateTime

Returns first next occurrence of specified DayOfWeek.

NextDay ( this start ) : System.DateTime

Returns DateTime increased by 24 hours ie Next Day.

NextMonth ( this current ) : System.DateTime

Returns the next month keeping the time component intact. Eg, 2012-12-05T06:40:20.005 => 2013-01-05T06:40:20.005 If the next month doesn't have that many days the last day of the next month is used. Eg, 2013-01-31T06:40:20.005 => 2013-02-28T06:40:20.005

NextYear ( this start ) : System.DateTime

Returns the same date (same Day, Month, Hour, Minute, Second etc) in the next calendar year. If that day does not exist in next year in same month, number of missing days is added to the last day in same month next year.

Noon ( this value ) : System.DateTime

Returns original DateTime value with time part set to Noon (12:00:00h).

Previous ( this start, DayOfWeek day ) : System.DateTime

Returns first next occurrence of specified DayOfWeek.

PreviousDay ( this start ) : System.DateTime

Returns DateTime decreased by 24h period ie Previous Day.

PreviousMonth ( this current ) : System.DateTime

Returns the previous month keeping the time component intact. Eg, 2010-01-20T06:40:20.005 => 2009-12-20T06:40:20.005 If the previous month doesn't have that many days the last day of the previous month is used. Eg, 2009-03-31T06:40:20.005 => 2009-02-28T06:40:20.005

PreviousYear ( this start ) : System.DateTime

Returns the same date (same Day, Month, Hour, Minute, Second etc) in the previous calendar year. If that day does not exist in previous year in same month, number of missing days is added to the last day in same month previous year.

Round ( this dateTime, RoundTo rt ) : System.DateTime
SameDay ( this current, System.DateTime date ) : bool

Determines whether the specified DateTime value is exactly the same day (day + month + year) then current

SameMonth ( this current, System.DateTime date ) : bool

Determines whether the specified DateTime value is exactly the same month (month + year) then current. Eg, 2015-12-01 and 2014-12-01 => False

SameYear ( this current, System.DateTime date ) : bool

Determines whether the specified DateTime value is exactly the same year then current. Eg, 2015-12-01 and 2015-01-01 => True

SetDate ( this value, int year ) : System.DateTime

Returns DateTime with changed Year part.

SetDate ( this value, int year, int month ) : System.DateTime

Returns DateTime with changed Year and Month part.

SetDate ( this value, int year, int month, int day ) : System.DateTime

Returns DateTime with changed Year, Month and Day part.

SetDay ( this value, int day ) : System.DateTime

Returns DateTime with changed Day part.

SetHour ( this originalDate, int hour ) : System.DateTime

Returns DateTime with changed Hour part.

SetMillisecond ( this originalDate, int millisecond ) : System.DateTime

Returns DateTime with changed Millisecond part.

SetMinute ( this originalDate, int minute ) : System.DateTime

Returns DateTime with changed Minute part.

SetMonth ( this value, int month ) : System.DateTime

Returns DateTime with changed Month part.

SetSecond ( this originalDate, int second ) : System.DateTime

Returns DateTime with changed Second part.

SetTime ( this originalDate, int hour ) : System.DateTime

Returns the original DateTime with Hour part changed to supplied hour parameter.

SetTime ( this originalDate, int hour, int minute ) : System.DateTime

Returns the original DateTime with Hour and Minute parts changed to supplied hour and minute parameters.

SetTime ( this originalDate, int hour, int minute, int second ) : System.DateTime

Returns the original DateTime with Hour, Minute and Second parts changed to supplied hour, minute and second parameters.

SetTime ( this originalDate, int hour, int minute, int second, int millisecond ) : System.DateTime

Returns the original DateTime with Hour, Minute, Second and Millisecond parts changed to supplied hour, minute, second and millisecond parameters.

SetYear ( this value, int year ) : System.DateTime

Returns DateTime with changed Year part.

SubtractBusinessDays ( this current, int days ) : System.DateTime

Subtracts the given number of business days to the DateTime.

WeekAfter ( this start ) : System.DateTime

Increases supplied DateTime for 7 days ie returns the Next Week.

WeekEarlier ( this start ) : System.DateTime

Decreases supplied DateTime for 7 days ie returns the Previous Week.

Private Methods

Method Description
StartOfWeek ( this dateTime ) : System.DateTime

Method Details

AddBusinessDays() public static method

Adds the given number of business days to the DateTime.
public static AddBusinessDays ( this current, int days ) : System.DateTime
current this The date to be changed.
days int Number of business days to be added.
return System.DateTime

At() public static method

Returns the given DateTime with hour and minutes set At given values.
public static At ( this current, int hour, int minute ) : System.DateTime
current this The current to be changed.
hour int The hour to set time to.
minute int The minute to set time to.
return System.DateTime

At() public static method

Returns the given DateTime with hour and minutes and seconds set At given values.
public static At ( this current, int hour, int minute, int second ) : System.DateTime
current this The current to be changed.
hour int The hour to set time to.
minute int The minute to set time to.
second int The second to set time to.
return System.DateTime

At() public static method

Returns the given DateTime with hour and minutes and seconds and milliseconds set At given values.
public static At ( this current, int hour, int minute, int second, int milliseconds ) : System.DateTime
current this The current to be changed.
hour int The hour to set time to.
minute int The minute to set time to.
second int The second to set time to.
milliseconds int The milliseconds to set time to.
return System.DateTime

BeginningOfDay() public static method

Returns the Start of the given day (the first millisecond of the given DateTime).
public static BeginningOfDay ( this date ) : System.DateTime
date this
return System.DateTime

BeginningOfDay() public static method

Returns the timezone-adjusted Start of the given day (the first millisecond of the given DateTime).
public static BeginningOfDay ( this date, int timezoneOffset ) : System.DateTime
date this
timezoneOffset int
return System.DateTime

DecreaseTime() public static method

Decreases the DateTime object with given TimeSpan value.
public static DecreaseTime ( this startDate, System.TimeSpan toSubtract ) : System.DateTime
startDate this
toSubtract System.TimeSpan
return System.DateTime

EndOfDay() public static method

Returns the very end of the given day (the last millisecond of the last hour for the given DateTime).
public static EndOfDay ( this date ) : System.DateTime
date this
return System.DateTime

EndOfDay() public static method

Returns the timezone-adjusted very end of the given day (the last millisecond of the last hour for the given DateTime).
public static EndOfDay ( this date, int timeZoneOffset ) : System.DateTime
date this
timeZoneOffset int
return System.DateTime

FirstDayOfMonth() public static method

Sets the day of the DateTime to the first day in that month.
public static FirstDayOfMonth ( this current ) : System.DateTime
current this The current to be changed.
return System.DateTime

FirstDayOfQuarter() public static method

Sets the day of the DateTime to the first day in that calendar quarter. credit to http://www.devcurry.com/2009/05/find-first-and-last-day-of-current.html
public static FirstDayOfQuarter ( this current ) : System.DateTime
current this
return System.DateTime

FirstDayOfWeek() public static method

Returns a DateTime adjusted to the beginning of the week.
the beginning of the week is controlled by the current Culture
public static FirstDayOfWeek ( this dateTime ) : System.DateTime
dateTime this The DateTime to adjust
return System.DateTime

FirstDayOfYear() public static method

Returns the first day of the year keeping the time component intact. Eg, 2011-02-04T06:40:20.005 => 2011-01-01T06:40:20.005
public static FirstDayOfYear ( this current ) : System.DateTime
current this The DateTime to adjust
return System.DateTime

IncreaseTime() public static method

Increases the DateTime object with given TimeSpan value.
public static IncreaseTime ( this startDate, System.TimeSpan toAdd ) : System.DateTime
startDate this
toAdd System.TimeSpan
return System.DateTime

IsAfter() public static method

Determines whether the specified DateTime value is After then current value.
public static IsAfter ( this current, System.DateTime toCompareWith ) : bool
current this The current value.
toCompareWith System.DateTime Value to compare with.
return bool

IsBefore() public static method

Determines whether the specified DateTime is before then current value.
public static IsBefore ( this current, System.DateTime toCompareWith ) : bool
current this The current value.
toCompareWith System.DateTime Value to compare with.
return bool

IsInFuture() public static method

Determine if a DateTime is in the future.
public static IsInFuture ( this dateTime ) : bool
dateTime this The date to be checked.
return bool

IsInPast() public static method

Determine if a DateTime is in the past.
public static IsInPast ( this dateTime ) : bool
dateTime this The date to be checked.
return bool

LastDayOfMonth() public static method

Sets the day of the DateTime to the last day in that month.
public static LastDayOfMonth ( this current ) : System.DateTime
current this The current DateTime to be changed.
return System.DateTime

LastDayOfQuarter() public static method

Sets the day of the DateTime to the last day in that calendar quarter. credit to http://www.devcurry.com/2009/05/find-first-and-last-day-of-current.html
public static LastDayOfQuarter ( this current ) : System.DateTime
current this
return System.DateTime

LastDayOfWeek() public static method

Returns the last day of the week keeping the time component intact. Eg, 2011-12-24T06:40:20.005 => 2011-12-25T06:40:20.005
public static LastDayOfWeek ( this current ) : System.DateTime
current this The DateTime to adjust
return System.DateTime

LastDayOfYear() public static method

Returns the last day of the year keeping the time component intact. Eg, 2011-12-24T06:40:20.005 => 2011-12-31T06:40:20.005
public static LastDayOfYear ( this current ) : System.DateTime
current this The DateTime to adjust
return System.DateTime

Midnight() public static method

Returns original DateTime value with time part set to midnight (alias for BeginningOfDay method).
public static Midnight ( this value ) : System.DateTime
value this
return System.DateTime

Next() public static method

Returns first next occurrence of specified DayOfWeek.
public static Next ( this start, DayOfWeek day ) : System.DateTime
start this
day DayOfWeek
return System.DateTime

NextDay() public static method

Returns DateTime increased by 24 hours ie Next Day.
public static NextDay ( this start ) : System.DateTime
start this
return System.DateTime

NextMonth() public static method

Returns the next month keeping the time component intact. Eg, 2012-12-05T06:40:20.005 => 2013-01-05T06:40:20.005 If the next month doesn't have that many days the last day of the next month is used. Eg, 2013-01-31T06:40:20.005 => 2013-02-28T06:40:20.005
public static NextMonth ( this current ) : System.DateTime
current this The DateTime to adjust
return System.DateTime

NextYear() public static method

Returns the same date (same Day, Month, Hour, Minute, Second etc) in the next calendar year. If that day does not exist in next year in same month, number of missing days is added to the last day in same month next year.
public static NextYear ( this start ) : System.DateTime
start this
return System.DateTime

Noon() public static method

Returns original DateTime value with time part set to Noon (12:00:00h).
public static Noon ( this value ) : System.DateTime
value this The find Noon for.
return System.DateTime

Previous() public static method

Returns first next occurrence of specified DayOfWeek.
public static Previous ( this start, DayOfWeek day ) : System.DateTime
start this
day DayOfWeek
return System.DateTime

PreviousDay() public static method

Returns DateTime decreased by 24h period ie Previous Day.
public static PreviousDay ( this start ) : System.DateTime
start this
return System.DateTime

PreviousMonth() public static method

Returns the previous month keeping the time component intact. Eg, 2010-01-20T06:40:20.005 => 2009-12-20T06:40:20.005 If the previous month doesn't have that many days the last day of the previous month is used. Eg, 2009-03-31T06:40:20.005 => 2009-02-28T06:40:20.005
public static PreviousMonth ( this current ) : System.DateTime
current this The DateTime to adjust
return System.DateTime

PreviousYear() public static method

Returns the same date (same Day, Month, Hour, Minute, Second etc) in the previous calendar year. If that day does not exist in previous year in same month, number of missing days is added to the last day in same month previous year.
public static PreviousYear ( this start ) : System.DateTime
start this
return System.DateTime

Round() public static method

public static Round ( this dateTime, RoundTo rt ) : System.DateTime
dateTime this
rt RoundTo
return System.DateTime

SameDay() public static method

Determines whether the specified DateTime value is exactly the same day (day + month + year) then current
public static SameDay ( this current, System.DateTime date ) : bool
current this The current value
date System.DateTime Value to compare with
return bool

SameMonth() public static method

Determines whether the specified DateTime value is exactly the same month (month + year) then current. Eg, 2015-12-01 and 2014-12-01 => False
public static SameMonth ( this current, System.DateTime date ) : bool
current this The current value
date System.DateTime Value to compare with
return bool

SameYear() public static method

Determines whether the specified DateTime value is exactly the same year then current. Eg, 2015-12-01 and 2015-01-01 => True
public static SameYear ( this current, System.DateTime date ) : bool
current this The current value
date System.DateTime Value to compare with
return bool

SetDate() public static method

Returns DateTime with changed Year part.
public static SetDate ( this value, int year ) : System.DateTime
value this
year int
return System.DateTime

SetDate() public static method

Returns DateTime with changed Year and Month part.
public static SetDate ( this value, int year, int month ) : System.DateTime
value this
year int
month int
return System.DateTime

SetDate() public static method

Returns DateTime with changed Year, Month and Day part.
public static SetDate ( this value, int year, int month, int day ) : System.DateTime
value this
year int
month int
day int
return System.DateTime

SetDay() public static method

Returns DateTime with changed Day part.
public static SetDay ( this value, int day ) : System.DateTime
value this
day int
return System.DateTime

SetHour() public static method

Returns DateTime with changed Hour part.
public static SetHour ( this originalDate, int hour ) : System.DateTime
originalDate this
hour int
return System.DateTime

SetMillisecond() public static method

Returns DateTime with changed Millisecond part.
public static SetMillisecond ( this originalDate, int millisecond ) : System.DateTime
originalDate this
millisecond int
return System.DateTime

SetMinute() public static method

Returns DateTime with changed Minute part.
public static SetMinute ( this originalDate, int minute ) : System.DateTime
originalDate this
minute int
return System.DateTime

SetMonth() public static method

Returns DateTime with changed Month part.
public static SetMonth ( this value, int month ) : System.DateTime
value this
month int
return System.DateTime

SetSecond() public static method

Returns DateTime with changed Second part.
public static SetSecond ( this originalDate, int second ) : System.DateTime
originalDate this
second int
return System.DateTime

SetTime() public static method

Returns the original DateTime with Hour part changed to supplied hour parameter.
public static SetTime ( this originalDate, int hour ) : System.DateTime
originalDate this
hour int
return System.DateTime

SetTime() public static method

Returns the original DateTime with Hour and Minute parts changed to supplied hour and minute parameters.
public static SetTime ( this originalDate, int hour, int minute ) : System.DateTime
originalDate this
hour int
minute int
return System.DateTime

SetTime() public static method

Returns the original DateTime with Hour, Minute and Second parts changed to supplied hour, minute and second parameters.
public static SetTime ( this originalDate, int hour, int minute, int second ) : System.DateTime
originalDate this
hour int
minute int
second int
return System.DateTime

SetTime() public static method

Returns the original DateTime with Hour, Minute, Second and Millisecond parts changed to supplied hour, minute, second and millisecond parameters.
public static SetTime ( this originalDate, int hour, int minute, int second, int millisecond ) : System.DateTime
originalDate this
hour int
minute int
second int
millisecond int
return System.DateTime

SetYear() public static method

Returns DateTime with changed Year part.
public static SetYear ( this value, int year ) : System.DateTime
value this
year int
return System.DateTime

SubtractBusinessDays() public static method

Subtracts the given number of business days to the DateTime.
public static SubtractBusinessDays ( this current, int days ) : System.DateTime
current this The date to be changed.
days int Number of business days to be subtracted.
return System.DateTime

WeekAfter() public static method

Increases supplied DateTime for 7 days ie returns the Next Week.
public static WeekAfter ( this start ) : System.DateTime
start this
return System.DateTime

WeekEarlier() public static method

Decreases supplied DateTime for 7 days ie returns the Previous Week.
public static WeekEarlier ( this start ) : System.DateTime
start this
return System.DateTime