Class DateTimeAndTimeSpanExtensions
Extensions for the DateTime
and TimeSpan
structs.
Inherited Members
Namespace: System
Assembly: Acoustics.Shared.dll
Syntax
public static class DateTimeAndTimeSpanExtensions
Methods
| Improve this Doc View SourceAbsolute(TimeSpan)
Declaration
public static TimeSpan Absolute(this TimeSpan span)
Parameters
Type | Name | Description |
---|---|---|
Time |
span |
Returns
Type | Description |
---|---|
Time |
Ceiling(DateTimeOffset, TimeSpan)
Declaration
public static DateTimeOffset Ceiling(this DateTimeOffset date, TimeSpan interval)
Parameters
Type | Name | Description |
---|---|---|
Date |
date | |
Time |
interval |
Returns
Type | Description |
---|---|
Date |
Divide(TimeSpan, Double)
Divides a timespan by an scalar value.
Declaration
public static TimeSpan Divide(this TimeSpan dividend, double divisor)
Parameters
Returns
Type | Description |
---|---|
Time |
Divide(TimeSpan, Int32)
Divides a timespan by an scalar value.
Declaration
public static TimeSpan Divide(this TimeSpan dividend, int divisor)
Parameters
Returns
Type | Description |
---|---|
Time |
Divide(TimeSpan, TimeSpan)
Divides a timespan by an timespan and returns a scalar factor.
Declaration
public static double Divide(this TimeSpan dividend, TimeSpan divisor)
Parameters
Returns
Type | Description |
---|---|
Double |
Floor(DateTimeOffset, TimeSpan)
Declaration
public static DateTimeOffset Floor(this DateTimeOffset date, TimeSpan interval)
Parameters
Type | Name | Description |
---|---|---|
Date |
date | |
Time |
interval |
Returns
Type | Description |
---|---|
Date |
Humanise(DateTime, DateTime, Boolean)
Get a human-readable string of difference between two DateTimes (eg. 2 hours, 2 hours ago, in 2 hours).
Declaration
public static string Humanise(this DateTime first, DateTime second, bool addSuffixOrPrefix = false)
Parameters
Type | Name | Description |
---|---|---|
Date |
first | First time (should be earlier). |
Date |
second | Second time (should be later). |
Boolean | addSuffixOrPrefix | The add Suffix Or Prefix. |
Returns
Type | Description |
---|---|
String | Human-readable string of difference between two DateTimes. |
Humanise(DateTimeOffset, DateTimeOffset, Boolean)
Get a human-readable string of difference between two DateTimes (eg. 2 hours, 2 hours ago, in 2 hours).
Declaration
public static string Humanise(this DateTimeOffset first, DateTimeOffset second, bool addSuffixOrPrefix = false)
Parameters
Type | Name | Description |
---|---|---|
Date |
first | First time (should be earlier). |
Date |
second | Second time (should be later). |
Boolean | addSuffixOrPrefix | The add Suffix Or Prefix. |
Returns
Type | Description |
---|---|
String | Human-readable string of difference between two DateTimes. |
Humanise(TimeSpan, Boolean)
Get a human readable representation of the time span.
Declaration
public static string Humanise(this TimeSpan timeSpan, bool addSuffixOrPrefix = false)
Parameters
Type | Name | Description |
---|---|---|
Time |
timeSpan | The time span. |
Boolean | addSuffixOrPrefix | True to add a suffix or prefix as appropriate. False to not add a suffix or prefix. |
Returns
Type | Description |
---|---|
String | Human readable representation of the time span. |
Max(TimeSpan, TimeSpan)
Declaration
public static TimeSpan Max(this TimeSpan t1, TimeSpan t2)
Parameters
Returns
Type | Description |
---|---|
Time |
Min(TimeSpan, TimeSpan)
Declaration
public static TimeSpan Min(this TimeSpan t1, TimeSpan t2)
Parameters
Returns
Type | Description |
---|---|
Time |
Modulo(TimeSpan, TimeSpan)
Divides a timespan by an timespan and the remainder.
Declaration
public static TimeSpan Modulo(this TimeSpan dividend, TimeSpan divisor)
Parameters
Returns
Type | Description |
---|---|
Time |
Multiply(TimeSpan, Double)
Multiplies a timespan by a double value.
Declaration
public static TimeSpan Multiply(this TimeSpan multiplicand, double multiplier)
Parameters
Returns
Type | Description |
---|---|
Time |
Multiply(TimeSpan, Int32)
Multiplies a timespan by a scalar value.
Declaration
public static TimeSpan Multiply(this TimeSpan multiplicand, int multiplier)
Parameters
Returns
Type | Description |
---|---|
Time |
Round(DateTime, TimeSpan)
Declaration
public static DateTime Round(this DateTime datetime, TimeSpan roundingInterval)
Parameters
Returns
Type | Description |
---|---|
Date |
Remarks
From: http://stackoverflow.com/questions/766626/is-there-a-better-way-in-c-sharp-to-round-a-datetime-to-the-nearest-5-seconds (Stackoverflow).
Round(DateTimeOffset, TimeSpan)
Declaration
public static DateTimeOffset Round(this DateTimeOffset date, TimeSpan roundingInterval)
Parameters
Type | Name | Description |
---|---|---|
Date |
date | |
Time |
roundingInterval |
Returns
Type | Description |
---|---|
Date |
Round(TimeSpan, TimeSpan)
Declaration
public static TimeSpan Round(this TimeSpan time, TimeSpan roundingInterval)
Parameters
Returns
Type | Description |
---|---|
Time |
Remarks
From: http://stackoverflow.com/questions/766626/is-there-a-better-way-in-c-sharp-to-round-a-datetime-to-the-nearest-5-seconds (Stackoverflow).
Round(TimeSpan, TimeSpan, MidpointRounding)
Declaration
public static TimeSpan Round(this TimeSpan time, TimeSpan roundingInterval, MidpointRounding roundingType)
Parameters
Type | Name | Description |
---|---|---|
Time |
time | |
Time |
roundingInterval | |
Midpoint |
roundingType |
Returns
Type | Description |
---|---|
Time |
Remarks
From: http://stackoverflow.com/questions/766626/is-there-a-better-way-in-c-sharp-to-round-a-datetime-to-the-nearest-5-seconds (Stackoverflow).
RoundToTimeOfDay(DateTimeOffset, TimeSpan, DateTimeAndTimeSpanExtensions.RoundingDirection)
Round a date to a time of day.
Declaration
public static DateTimeOffset RoundToTimeOfDay(this DateTimeOffset date, TimeSpan timeOfDay, DateTimeAndTimeSpanExtensions.RoundingDirection direction)
Parameters
Type | Name | Description |
---|---|---|
Date |
date | The date to round. |
Time |
timeOfDay | The time of day to round to. |
Date |
direction | The behaviour of the rounding operation. |
Returns
Type | Description |
---|---|
Date |
A rounded date. |
Remarks
Unlike the other rounding methods (which accept an interval), this method
will only output values that are 24-hours apart so that values always align
to the supplied timeOfDay
.
ToIso8601SafeString(DateTimeOffset)
Formats a date in an ISO8601 format that is compact and does not contain colons.
Declaration
public static string ToIso8601SafeString(this DateTimeOffset date)
Parameters
Type | Name | Description |
---|---|---|
Date |
date | The date to convert to a string. |
Returns
Type | Description |
---|---|
String | The resulting string. |
ToJavascriptTimestamp(DateTime)
Gets the DateTime formatted as a javascript timestamp.
Declaration
public static long ToJavascriptTimestamp(this DateTime value)
Parameters
Type | Name | Description |
---|---|---|
Date |
value | The value. |
Returns
Type | Description |
---|---|
Int64 | Javascript timestamp. |
ToJavascriptTimestamp(DateTimeOffset)
Gets the DateTimeOffset formatted as a javascript timestamp.
Declaration
public static long ToJavascriptTimestamp(this DateTimeOffset value)
Parameters
Type | Name | Description |
---|---|---|
Date |
value | The value. |
Returns
Type | Description |
---|---|
Int64 | Javascript timestamp. |
ToTimeZoneString(TimeSpan)
Gets the minutes and seconds of a time span in the format required for an offset from UTC.
Declaration
public static string ToTimeZoneString(this TimeSpan ts)
Parameters
Type | Name | Description |
---|---|---|
Time |
ts | The time span. |
Returns
Type | Description |
---|---|
String | Time zone offset formatted string. |