Class DateTimes
Contains methods for manipulating values.
Inheritance
System.Object
DateTimes
Assembly: FFT.TimeStamps.dll
Syntax
public static class DateTimes : object
Methods
|
Improve this Doc
View Source
AssumeKind(DateTime, DateTimeKind)
Creates a DateTime object with the same value but with the
property set to kind
. No timezone conversion is performed.
Declaration
public static DateTime AssumeKind(this DateTime value, DateTimeKind kind)
Parameters
Type |
Name |
Description |
DateTime |
value |
|
DateTimeKind |
kind |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
AssumeLocal(DateTime)
Creates a DateTime object with the same value but with the
property set to . No timezone conversion is performed.
Declaration
public static DateTime AssumeLocal(this DateTime value)
Parameters
Type |
Name |
Description |
DateTime |
value |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
AssumeUniversal(DateTime)
Creates a DateTime object with the same value but with the
property set to . No timezone conversion is performed.
Declaration
public static DateTime AssumeUniversal(this DateTime value)
Parameters
Type |
Name |
Description |
DateTime |
value |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
AssumeUnspecified(DateTime)
Creates a DateTime object with the same value but with the
property set to . No timezone conversion is performed.
Declaration
public static DateTime AssumeUnspecified(this DateTime value)
Parameters
Type |
Name |
Description |
DateTime |
value |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
FromUnixMilliseconds(Int64, DateTimeKind)
Creates a timestamp the given number of milliseconds after midnight, 1 January 1970, of the kind
specified.
Declaration
public static DateTime FromUnixMilliseconds(long unixMilliseconds, DateTimeKind kind)
Parameters
Type |
Name |
Description |
System.Int64 |
unixMilliseconds |
|
DateTimeKind |
kind |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
FromUnixSeconds(Int64, DateTimeKind)
Creates a timestamp the given number of seconds after midnight, 1 January 1970, of the kind
specified.
Declaration
public static DateTime FromUnixSeconds(long unixSeconds, DateTimeKind kind)
Parameters
Type |
Name |
Description |
System.Int64 |
unixSeconds |
|
DateTimeKind |
kind |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
GetNext(DateTime, TimeOfWeek)
Calculates the moment at timeOfWeek
that first occurs at or after timestamp
.
Declaration
public static DateTime GetNext(this DateTime timestamp, TimeOfWeek timeOfWeek)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
TimeOfWeek |
timeOfWeek |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
GetNext(DateTime, TimeSpan)
Calculates the moment at timeOfDay
that first occurs at or after timestamp
.
You will get unexpected results if timeOfDay
is less than zero or greater than 24 hours.
Declaration
public static DateTime GetNext(this DateTime timestamp, TimeSpan timeOfDay)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
TimeSpan |
timeOfDay |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
GetPrevious(DateTime, TimeOfWeek)
Calculates the moment at timeOfWeek
that first occurs at or before timestamp
.
Declaration
public static DateTime GetPrevious(this DateTime timestamp, TimeOfWeek timeOfWeek)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
TimeOfWeek |
timeOfWeek |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
GetPrevious(DateTime, TimeSpan)
Calculates the moment at timeOfDay
that mostly recently occurs at or before timestamp
.
You will get unexpected results if timeOfDay
is less than zero or greater than 24 hours.
Declaration
public static DateTime GetPrevious(this DateTime timestamp, TimeSpan timeOfDay)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
TimeSpan |
timeOfDay |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
IsWeekend(DateTime)
Returns True if the given time's property is a weekend day (Saturday or Sunday).
Declaration
public static bool IsWeekend(this DateTime target)
Parameters
Type |
Name |
Description |
DateTime |
target |
|
Returns
Type |
Description |
System.Boolean |
|
|
Improve this Doc
View Source
SkipTheseDatesMovingBackward(DateTime, IEnumerable<DateTime>)
Retards the given time 24 hours at a time until the datesToSkip no longer contain the result.
Matching is exact. Skipping only happens if the datesToSkip
values and the date
contain the same value.
If your intention is to skip exact dates, you would be best to make sure that the date
value is zero before calling this method.
Declaration
public static DateTime SkipTheseDatesMovingBackward(this DateTime date, IEnumerable<DateTime> datesToSkip)
Parameters
Type |
Name |
Description |
DateTime |
date |
|
IEnumerable<DateTime> |
datesToSkip |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
SkipTheseDatesMovingForward(DateTime, IEnumerable<DateTime>)
Advances the given time 24 hours at a time until the datesToSkip no longer contain the result.
Matching is exact. Skipping only happens if the datesToSkip
values and the date
contain the same value.
If your intention is to skip exact dates, you would be best to make sure that the date
value is zero before calling this method.
Declaration
public static DateTime SkipTheseDatesMovingForward(this DateTime date, IEnumerable<DateTime> datesToSkip)
Parameters
Type |
Name |
Description |
DateTime |
date |
|
IEnumerable<DateTime> |
datesToSkip |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
SkipWeekendAndTheseDatesMovingBackward(DateTime, IEnumerable<DateTime>)
Gets the closest date on or before the given date
that does not fall on the weekend or in the datesToSkip
.
Declaration
public static DateTime SkipWeekendAndTheseDatesMovingBackward(this DateTime date, IEnumerable<DateTime> datesToSkip)
Parameters
Type |
Name |
Description |
DateTime |
date |
|
IEnumerable<DateTime> |
datesToSkip |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
SkipWeekendAndTheseDatesMovingForward(DateTime, IEnumerable<DateTime>)
Gets the closest date on or after the given date
that does not fall on the weekend or in the datesToSkip
.
Declaration
public static DateTime SkipWeekendAndTheseDatesMovingForward(this DateTime date, IEnumerable<DateTime> datesToSkip)
Parameters
Type |
Name |
Description |
DateTime |
date |
|
IEnumerable<DateTime> |
datesToSkip |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
SkipWeekendMovingBackward(DateTime)
Retards the given time 24 hours at a time until its property is no longer Saturday or Sunday.
Declaration
public static DateTime SkipWeekendMovingBackward(this DateTime date)
Parameters
Type |
Name |
Description |
DateTime |
date |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
SkipWeekendMovingForward(DateTime)
Advances the given time 24 hours at a time until its property is no longer Saturday or Sunday.
Declaration
public static DateTime SkipWeekendMovingForward(this DateTime date)
Parameters
Type |
Name |
Description |
DateTime |
date |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToDayCeiling(DateTime)
Rounds the timestamp up to the start of the next day.
If the timestamp is at an exact day, it returns a copy of the same timestamp.
Declaration
public static DateTime ToDayCeiling(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToDayFloor(DateTime)
Rounds the timestamp down to the start of the day.
If the timestamp is at an exact day, it returns a copy of the same timestamp.
Declaration
public static DateTime ToDayFloor(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToFixedIntervalCeiling(DateTime, DateTime, TimeSpan)
Divides time from intervalStart
into evenly-sized periods (intervals) of length intervalLength
and returns the beginning of the next interval to start after timestamp
.
If the timestamp
is at an exact interval start, it returns a copy of the same timestamp
.
Declaration
public static DateTime ToFixedIntervalCeiling(this DateTime timestamp, DateTime intervalStart, TimeSpan intervalLength)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
DateTime |
intervalStart |
|
TimeSpan |
intervalLength |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToFixedIntervalFloor(DateTime, DateTime, TimeSpan)
Divides time from intervalStart
into evenly-sized periods (intervals) of length intervalLength
and returns the beginning of the interval in progress at timestamp
.
If the timestamp
is at an exact interval start, it returns a copy of the same timestamp
.
Declaration
public static DateTime ToFixedIntervalFloor(this DateTime timestamp, DateTime intervalStart, TimeSpan intervalLength)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
DateTime |
intervalStart |
|
TimeSpan |
intervalLength |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToFixedIntervalIndex(DateTime, DateTime, TimeSpan)
Calculates the zero-based index of the interval in progress.
Declaration
public static int ToFixedIntervalIndex(this DateTime timestamp, DateTime intervalStart, TimeSpan intervalLength)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
DateTime |
intervalStart |
|
TimeSpan |
intervalLength |
|
Returns
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
ToHourCeiling(DateTime)
Rounds the timestamp up to the start of the next hour
If the timestamp is at an exact hour, it returns a copy of the same timestamp.
Declaration
public static DateTime ToHourCeiling(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToHourFloor(DateTime)
Rounds the timestamp down to the start of the hour.
If the timestamp is at an exact hour, it returns a copy of the same timestamp.
Declaration
public static DateTime ToHourFloor(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToMillisecondCeiling(DateTime)
Rounds the given timestamp up to the start of the millisecond.
If the timestamp is at an exact millisecond, it returns a copy of the same timestamp.
Declaration
public static DateTime ToMillisecondCeiling(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToMillisecondFloor(DateTime)
Rounds the given timestamp down to the start of the millisecond.
If the timestamp is at an exact millisecond, it returns a copy of the same timestamp.
Declaration
public static DateTime ToMillisecondFloor(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToMinuteCeiling(DateTime)
Rounds the timestamp up to the start of the next minute
If the timestamp is at an exact minute, it returns a copy of the same timestamp.
Declaration
public static DateTime ToMinuteCeiling(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToMinuteFloor(DateTime)
Rounds the timestamp down to the start of the minute
If the timestamp is at an exact minute, it returns a copy of the same timestamp.
Declaration
public static DateTime ToMinuteFloor(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToMinuteOfDayIndex(DateTime)
Rounds the minute down to the start of the minute and then
returns the zero-based index of the minute within the day.
Values returned range from 0 to 1439.
Declaration
public static int ToMinuteOfDayIndex(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
ToMinuteOfWeekIndex(DateTime)
Rounds the minute down to the start of the minute and then
returns zero-based index of the minute within the week.
Values returned range from 0 to 6 * 1440 - 1.
Declaration
public static int ToMinuteOfWeekIndex(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
ToMonthCeiling(DateTime)
Rounds the given timestamp up to the start of the next month.
If the timestamp is at the exact beginning of a month, it returns a copy of the same timestamp.
Declaration
public static DateTime ToMonthCeiling(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToMonthFloor(DateTime)
Rounds the given timestamp down to the beginning of the month.
If the timestamp is at the exact beginning of a month, it returns a copy of the same timestamp.
Declaration
public static DateTime ToMonthFloor(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToPeriodOfWeekCeiling(DateTime, TimeSpan)
Divides a week into periods defined by a length in minutes, and a starting offset that shifts the periods' start/end times.
Then finds the end of a period that includes the given timestamp.
Beginning of the first period is considered to be midnight, Sunday.
Declaration
public static DateTime ToPeriodOfWeekCeiling(this DateTime timestamp, TimeSpan periodLength)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
TimeSpan |
periodLength |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToPeriodOfWeekCeiling(DateTime, TimeSpan, TimeSpan)
Divides a week into periods defined by a length in minutes, and a starting offset that shifts the periods' start/end times.
Then finds the end of a period that includes the given timestamp.
Beginning of the first period is considered to be midnight, Sunday, PLUS periodOffset
.
Declaration
public static DateTime ToPeriodOfWeekCeiling(this DateTime timestamp, TimeSpan periodLength, TimeSpan periodOffset)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
TimeSpan |
periodLength |
|
TimeSpan |
periodOffset |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToPeriodOfWeekFloor(DateTime, TimeSpan)
Divides a week into periods defined by a length in minutes, and a starting offset that shifts the periods' start/end times.
Then finds the start of a period that includes the given timestamp.
Beginning of the first period is considered to be midnight, Sunday.
Declaration
public static DateTime ToPeriodOfWeekFloor(this DateTime timestamp, TimeSpan periodLength)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
TimeSpan |
periodLength |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToPeriodOfWeekFloor(DateTime, TimeSpan, TimeSpan)
Divides a week into periods defined by a length in minutes, and a starting offset that shifts the periods' start/end times.
Then finds the start of a period that includes the given timestamp.
Beginning of the first period is considered to be midnight, Sunday, PLUS periodOffset
.
Declaration
public static DateTime ToPeriodOfWeekFloor(this DateTime timestamp, TimeSpan periodLength, TimeSpan periodOffset)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
TimeSpan |
periodLength |
|
TimeSpan |
periodOffset |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToPeriodOfWeekIndex(DateTime, TimeSpan)
Divides the week into periods of length periodLength
, and then calculates
the zero-based index of the period at given time timestamp
.
Beginning of the first period is considered to be midnight, Sunday.
Periods include the first tick (index == 0) and exclude the the first tick of the next period (index < periodLength).
Declaration
public static int ToPeriodOfWeekIndex(this DateTime timestamp, TimeSpan periodLength)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
TimeSpan |
periodLength |
|
Returns
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
ToPeriodOfWeekIndex(DateTime, TimeSpan, TimeSpan)
Divides the week into periods of length periodLength
, and then calculates
the zero-based index of the period at given time timestamp
.
Beginning of the first period is considered to be midnight, Sunday, PLUS periodOffset
.
Periods include the first tick (index == 0) and exclude the the first tick of the next period (index < periodLength).
Declaration
public static int ToPeriodOfWeekIndex(this DateTime timestamp, TimeSpan periodLength, TimeSpan periodOffset)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
TimeSpan |
periodLength |
|
TimeSpan |
periodOffset |
|
Returns
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
ToSecondCeiling(DateTime)
Rounds the given timestamp up to the start of the next second.
If the timestamp is at an exact second, it returns a copy of the same timestamp.
Declaration
public static DateTime ToSecondCeiling(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToSecondFloor(DateTime)
Rounds the given timestamp down to the start of the second.
If the timestamp is at an exact second, it returns a copy of the same timestamp.
Declaration
public static DateTime ToSecondFloor(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToSecondOfDayIndex(DateTime)
Rounds the timestamp
down to the start of the second and then
returns zero-based index of the second within the day.
Values returned range from 0 to 1440 * 60 - 1.
Declaration
public static int ToSecondOfDayIndex(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
ToSecondOfWeekIndex(DateTime)
Rounds the second down to the start of the second and then
returns zero-based index of the second within the week.
Values returned range from 0 to 6 * 1440 * 60 - 1.
Declaration
public static int ToSecondOfWeekIndex(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
ToUnixMillieconds(DateTime)
Gets the number of milliseconds since Midnight, 1 January 1970, UTC.
in the same timezone as the given timestamp
.
Declaration
public static long ToUnixMillieconds(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
System.Int64 |
|
|
Improve this Doc
View Source
ToUnixSeconds(DateTime)
Gets the number of seconds since Midnight, 1 January 1970,
in the same timezone as the given timestamp
.
Declaration
public static long ToUnixSeconds(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
System.Int64 |
|
|
Improve this Doc
View Source
ToWeekCeiling(DateTime)
Rounds the given timestamp up to the end of the week (00:00:00 Sunday), returning the same timestamp if it is already on Sunday midnight.
Declaration
public static DateTime ToWeekCeiling(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
DateTime |
|
|
Improve this Doc
View Source
ToWeekFloor(DateTime)
Rounds the given timestamp down to the start of the week (00:00:00 Sunday), returning the same timestamp if it is already on Sunday midnight.
Declaration
public static DateTime ToWeekFloor(this DateTime timestamp)
Parameters
Type |
Name |
Description |
DateTime |
timestamp |
|
Returns
Type |
Description |
DateTime |
|