Assembly: OptimaJet.Workflow.Core

Class HelperDateTime

OptimaJet.Workflow.Core.Helpers.HelperDateTime

Provides utilities for comparing DateTime values, parsing and applying intervals, and truncating TimeSpan values.

public static class HelperDateTime

Methods

public static int CompareWithoutSeconds(this DateTime d1, DateTime d2) #
Compares two DateTime values without considering any part of either value below the minute.

Parameters

Name
Type
Description
d1
DateTime
The first value to compare.
d2
DateTime
The second value to compare.

Returns

Type
Description
Int32
0 when the values have equal DateTime.Date, DateTime.Hour, and DateTime.Minute components; otherwise, the result of DateTime.CompareTo(DateTime).
public static TimeSpan GetInterval(string value) #
Parses a fixed-duration interval as a TimeSpan.

Parameters

Name
Type
Description
value
String
The interval to parse. A value that can be parsed as an int represents milliseconds.

Returns

Type
Description
TimeSpan
The parsed TimeSpan, or TimeSpan.Zero when value is neither an integer nor a valid fixed-duration interval.

Exceptions

Type
Description
ArgumentNullException
Thrown when value is null.
ArgumentException
Thrown when value contains a working-time component.

Remarks

A fixed-duration interval can combine day, hour, minute, second, and millisecond components in any order.

Example

"1500" represents 1,500 milliseconds. Both "2d 4h 30m" and "2 days 4 hours 30 minutes" represent two days, four hours, and thirty minutes.
public static TimeSpan GetIntervalFor(DateTime oldDateTime, string intervalString) #
Calculates the difference produced by applying an interval to a specified DateTime.

Parameters

Name
Type
Description
oldDateTime
DateTime
The value from which to calculate the interval difference.
intervalString
String
The interval to apply. A value that can be parsed as an int represents milliseconds.

Returns

Type
Description
TimeSpan
The adjusted value minus oldDateTime, represented as a TimeSpan.

Exceptions

Type
Description
ArgumentNullException
Thrown when intervalString is null.
ArgumentException
Thrown when intervalString contains a working-time component.
ArgumentOutOfRangeException
Thrown when applying the interval produces a value outside the range supported by DateTime.

Remarks

For a component-based interval, the result can depend on oldDateTime because year and month components are applied as calendar adjustments.

Example

Examples of accepted interval strings are "1500", "1 month 2 days 3 hours", and "1mm 2d 3h".
public static TimeSpan GetInterval(this DateTime dateTime, string intervalString) #
Calculates the difference produced by applying an interval to dateTime.

Parameters

Name
Type
Description
dateTime
DateTime
The value from which to calculate the interval difference.
intervalString
String
The interval to apply. A value that can be parsed as an int represents milliseconds.

Returns

Type
Description
TimeSpan
The adjusted value minus dateTime, represented as a TimeSpan.

Exceptions

Type
Description
ArgumentNullException
Thrown when intervalString is null.
ArgumentException
Thrown when intervalString contains a working-time component.
ArgumentOutOfRangeException
Thrown when applying the interval produces a value outside the range supported by DateTime.

Remarks

This extension method is equivalent to HelperDateTime.GetIntervalFor(DateTime, string).

Example

Examples of accepted interval strings are "1500", "1 month 2 days 3 hours", and "1mm 2d 3h".
public static DateTime AddIntervalFor(DateTime dateTime, string intervalString) #
Adds the components of an interval to a specified DateTime.

Parameters

Name
Type
Description
dateTime
DateTime
The value to adjust.
intervalString
String
The interval to add. A value that can be parsed as an int represents milliseconds.

Returns

Type
Description
DateTime
The adjusted DateTime.

Exceptions

Type
Description
ArgumentNullException
Thrown when intervalString is null.
ArgumentException
Thrown when intervalString contains a working-time component.
ArgumentOutOfRangeException
Thrown when applying the interval produces a value outside the range supported by DateTime.

Remarks

Nonnumeric intervals can contain year, month, day, hour, minute, second, and millisecond components, which are applied in that order.

Example

"1500" adds 1,500 milliseconds. Both "1 year 2 months 3 days 4 hours 5 minutes 6 seconds 700 milliseconds" and "1y 2mm 3d 4h 5m 6s 700ms" use the supported component formats.
public static DateTime AddInterval(this DateTime dateTime, string intervalString) #
Adds the components of an interval to dateTime.

Parameters

Name
Type
Description
dateTime
DateTime
The value to adjust.
intervalString
String
The interval to add. A value that can be parsed as an int represents milliseconds.

Returns

Type
Description
DateTime
The adjusted DateTime.

Exceptions

Type
Description
ArgumentNullException
Thrown when intervalString is null.
ArgumentException
Thrown when intervalString contains a working-time component.
ArgumentOutOfRangeException
Thrown when applying the interval produces a value outside the range supported by DateTime.

Remarks

This extension method is equivalent to HelperDateTime.AddIntervalFor(DateTime, string).

Example

"1500" adds 1,500 milliseconds. Both "1 year 2 months 3 days 4 hours 5 minutes 6 seconds 700 milliseconds" and "1y 2mm 3d 4h 5m 6s 700ms" use the supported component formats.
public static DateTime SubtractIntervalFor(DateTime dateTime, string intervalString) #
Subtracts the recognized components of a nonnumeric interval from a specified DateTime.

Parameters

Name
Type
Description
dateTime
DateTime
The value to adjust.
intervalString
String
The interval to apply.

Returns

Type
Description
DateTime
The adjusted DateTime.

Exceptions

Type
Description
ArgumentNullException
Thrown when intervalString is null.
ArgumentException
Thrown when intervalString contains a working-time component.
ArgumentOutOfRangeException
Thrown when applying the interval produces a value outside the range supported by DateTime.

Remarks

A value that can be parsed as an int is added to dateTime as a millisecond offset. For other values, recognized year, month, day, hour, minute, second, and millisecond components are subtracted in that order.

Example

Both "1 month 2 days 3 hours" and "1mm 2d 3h" use the supported component formats. An integer can be supplied as "1500"; it follows the millisecond-offset behavior described above.
public static DateTime SubtractInterval(this DateTime dateTime, string intervalString) #
Subtracts the recognized components of a nonnumeric interval from dateTime.

Parameters

Name
Type
Description
dateTime
DateTime
The value to adjust.
intervalString
String
The interval to apply.

Returns

Type
Description
DateTime
The adjusted DateTime.

Exceptions

Type
Description
ArgumentNullException
Thrown when intervalString is null.
ArgumentException
Thrown when intervalString contains a working-time component.
ArgumentOutOfRangeException
Thrown when applying the interval produces a value outside the range supported by DateTime.

Remarks

This extension method is equivalent to HelperDateTime.SubtractIntervalFor(DateTime, string); consequently, an integer interval is added as a millisecond offset.

Example

Both "1 month 2 days 3 hours" and "1mm 2d 3h" use the supported component formats. An integer can be supplied as "1500"; it is added as a millisecond offset.
public static TimeSpan Floor(this TimeSpan timeSpan) #
Removes the sub-minute portion from a TimeSpan.

Parameters

Name
Type
Description
timeSpan
TimeSpan
The value to truncate to whole minutes.

Returns

Type
Description
TimeSpan
A TimeSpan whose TimeSpan.Seconds and TimeSpan.Milliseconds components are zero.