PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.DateTimeExtensions Class Reference

Provides some useful extension methods for DateTime values. More...

Static Public Member Functions

static bool IsWithinRange (this DateTime value, DateTime start, DateTime end)
 Calculates whether or not a provided DateTime is within the provided range.
static string AsHoursAndMinutes (this DateTime value)
 Returns a string representation of the form HH:mm for a DateTime.
static string AsTimeString (this DateTime value)
 Returns a string representation of the form HH:mm:ss for a DateTime.
static long MillisecondsSinceStartOfDay (this DateTime value)
 Calculates the number of milliseconds since the start of the day for a given DateTime value.
static DateTime StartOfDay (this DateTime value)
 Calculates the DateTime of the start of the day for a provided DateTime value.
static DateTimeOffset StartOfDay (this DateTimeOffset value)
 Returns the start of day for a DateTimeOffset.
static DateTime EndOfDay (this DateTime value)
 Calculates the DateTime of the end of the day for a provided DateTime value.
static DateTime AsTimeOnly (this DateTime value)
 Gets a DateTime value which has the same time components as the provided subject with minimum values (typically 0 or 1) for the date components.
static DateTime WithTime (this DateTime value, int hour, int minute, int second, int millisecond=0)
 Gets a new DateTime with the time component mutated.
static DateTime WithTime (this DateTime value, TimeSpan time)
 Produces a new DateTime with the time mutated to the time specified by the provided TimeSpan, clamped to within 24 hours.
static DateTime TruncateMicroseconds (this DateTime value)
 Provides a new DateTime with all components from the subject except Microseconds, which are truncated.
static DateTime TruncateMilliseconds (this DateTime value)
 Provides a new DateTime with all components from the subject except Milliseconds, which are truncated.
static DateTime ToKind (this DateTime value, DateTimeKind kind)
 Provides a new DateTime object with the DateTimeKind set as required.
static DateTime WithKind (this DateTime value, DateTimeKind kind)
 Provides a new DateTime object with the DateTimeKind set as required. Note that this doesn't convert DateTime objects between, eg UTC and Local times: the.
static bool IsBetween (this DateTime subject, DateTime before, DateTime after)
 Returns true when the subject date-time is between the provided before and after values.
static DateTime TruncateSeconds (this DateTime value)
 Provides a new DateTime with all components from the subject except Seconds, which are truncated.
static DateTime TruncateMinutes (this DateTime value)
 Provides a new DateTime with all components from the subject except Minutes, which are truncated.
static DateTime TruncateHours (this DateTime value)
 Provides a new DateTime with all components from the subject except Hours, which are truncated.
static DateTime TruncateDays (this DateTime value)
 Provides a new DateTime with all components from the subject except Days, which are truncated.
static DateTime TruncateMonths (this DateTime value)
 Provides a new DateTime with all components from the subject except Months, which are truncated.
static int Microseconds (this DateTime value)
 Gets the microseconds component for a DateTime value.

Detailed Description

Provides some useful extension methods for DateTime values.

Member Function Documentation

◆ AsHoursAndMinutes()

string PeanutButter.Utils.DateTimeExtensions.AsHoursAndMinutes ( this DateTime value)
static

Returns a string representation of the form HH:mm for a DateTime.

Parameters
valueDatetime subject
Returns
String representation of the time part of the subject, in the format HH:mm

◆ AsTimeOnly()

DateTime PeanutButter.Utils.DateTimeExtensions.AsTimeOnly ( this DateTime value)
static

Gets a DateTime value which has the same time components as the provided subject with minimum values (typically 0 or 1) for the date components.

Parameters
valueSubject DateTime to operate on
Returns
new DateTime with date components set from DateTime.MinValue and time components set from the subject

◆ AsTimeString()

string PeanutButter.Utils.DateTimeExtensions.AsTimeString ( this DateTime value)
static

Returns a string representation of the form HH:mm:ss for a DateTime.

Parameters
valueDatetime subject
Returns
String representation of the time part of the subject, in the format HH:mm:ss

◆ EndOfDay()

DateTime PeanutButter.Utils.DateTimeExtensions.EndOfDay ( this DateTime value)
static

Calculates the DateTime of the end of the day for a provided DateTime value.

Parameters
valueSubject DateTime to calculate the end of day for
Returns
A new DateTime value which represents the end of the day for the subject DateTime

◆ IsBetween()

bool PeanutButter.Utils.DateTimeExtensions.IsBetween ( this DateTime subject,
DateTime before,
DateTime after )
static

Returns true when the subject date-time is between the provided before and after values.

Parameters
subject
before
after
Returns

◆ IsWithinRange()

bool PeanutButter.Utils.DateTimeExtensions.IsWithinRange ( this DateTime value,
DateTime start,
DateTime end )
static

Calculates whether or not a provided DateTime is within the provided range.

Parameters
valueDateTime subject to test
startMinimum value of DateTime range
endMaximumValue of DateTime range
Returns
True if the value is within the provided range or false if it is not

◆ Microseconds()

int PeanutButter.Utils.DateTimeExtensions.Microseconds ( this DateTime value)
static

Gets the microseconds component for a DateTime value.

Parameters
valueSubject DateTime to operate on
Returns
Microseconds component of the subject DateTime value

◆ MillisecondsSinceStartOfDay()

long PeanutButter.Utils.DateTimeExtensions.MillisecondsSinceStartOfDay ( this DateTime value)
static

Calculates the number of milliseconds since the start of the day for a given DateTime value.

Parameters
valueDateTime subject to calculate for
Returns
Number of milliseconds since the start of the day for the subject DateTime

◆ StartOfDay() [1/2]

DateTime PeanutButter.Utils.DateTimeExtensions.StartOfDay ( this DateTime value)
static

Calculates the DateTime of the start of the day for a provided DateTime value.

Parameters
valueSubject DateTime to calculate the start of day for
Returns
A new DateTime value which represents the start of the day for the subject DateTime

◆ StartOfDay() [2/2]

DateTimeOffset PeanutButter.Utils.DateTimeExtensions.StartOfDay ( this DateTimeOffset value)
static

Returns the start of day for a DateTimeOffset.

Parameters
value
Returns

◆ ToKind()

DateTime PeanutButter.Utils.DateTimeExtensions.ToKind ( this DateTime value,
DateTimeKind kind )
static

Provides a new DateTime object with the DateTimeKind set as required.

Parameters
value
kind
Returns

◆ TruncateDays()

DateTime PeanutButter.Utils.DateTimeExtensions.TruncateDays ( this DateTime value)
static

Provides a new DateTime with all components from the subject except Days, which are truncated.

Parameters
valueSubject DateTime to start with
Returns
New DateTime with all components except milliDays set from the subject. Days are set to zero.

◆ TruncateHours()

DateTime PeanutButter.Utils.DateTimeExtensions.TruncateHours ( this DateTime value)
static

Provides a new DateTime with all components from the subject except Hours, which are truncated.

Parameters
valueSubject DateTime to start with
Returns
New DateTime with all components except milliHours set from the subject. Hours are set to zero.

◆ TruncateMicroseconds()

DateTime PeanutButter.Utils.DateTimeExtensions.TruncateMicroseconds ( this DateTime value)
static

Provides a new DateTime with all components from the subject except Microseconds, which are truncated.

Parameters
valueSubject DateTime to start with
Returns
New DateTime with all components except milliseconds set from the subject. Microseconds are set to zero.

◆ TruncateMilliseconds()

DateTime PeanutButter.Utils.DateTimeExtensions.TruncateMilliseconds ( this DateTime value)
static

Provides a new DateTime with all components from the subject except Milliseconds, which are truncated.

Parameters
valueSubject DateTime to start with
Returns
New DateTime with all components except milliseconds set from the subject. Milliseconds are set to zero.

◆ TruncateMinutes()

DateTime PeanutButter.Utils.DateTimeExtensions.TruncateMinutes ( this DateTime value)
static

Provides a new DateTime with all components from the subject except Minutes, which are truncated.

Parameters
valueSubject DateTime to start with
Returns
New DateTime with all components except milliMinutes set from the subject. Minutes are set to zero.

◆ TruncateMonths()

DateTime PeanutButter.Utils.DateTimeExtensions.TruncateMonths ( this DateTime value)
static

Provides a new DateTime with all components from the subject except Months, which are truncated.

Parameters
valueSubject DateTime to start with
Returns
New DateTime with all components except milliMonths set from the subject. Months are set to zero.

◆ TruncateSeconds()

DateTime PeanutButter.Utils.DateTimeExtensions.TruncateSeconds ( this DateTime value)
static

Provides a new DateTime with all components from the subject except Seconds, which are truncated.

Parameters
valueSubject DateTime to start with
Returns
New DateTime with all components except milliSeconds set from the subject. Seconds are set to zero.

◆ WithKind()

DateTime PeanutButter.Utils.DateTimeExtensions.WithKind ( this DateTime value,
DateTimeKind kind )
static

Provides a new DateTime object with the DateTimeKind set as required. Note that this doesn't convert DateTime objects between, eg UTC and Local times: the.

Parameters
value
kind
Returns

◆ WithTime() [1/2]

DateTime PeanutButter.Utils.DateTimeExtensions.WithTime ( this DateTime value,
int hour,
int minute,
int second,
int millisecond = 0 )
static

Gets a new DateTime with the time component mutated.

Parameters
valueSubject DateTime to start with
hourHours to set on result
minuteMinutes to set on result
secondSeconds to set on result
millisecondMilliseconds to set on result
Returns
A new DateTime with the date component copied from the subject and the time component set from provided arguments

◆ WithTime() [2/2]

DateTime PeanutButter.Utils.DateTimeExtensions.WithTime ( this DateTime value,
TimeSpan time )
static

Produces a new DateTime with the time mutated to the time specified by the provided TimeSpan, clamped to within 24 hours.

Parameters
valueSubject DateTime to start with
timeRequired time
Returns
new DateTime with provided time

The documentation for this class was generated from the following file:
  • source/Utils/PeanutButter.Utils/DateTimeExtensions.cs