Class HelperDateTime
OptimaJet.Workflow.Core.Helpers.HelperDateTime
Provides utilities for comparing DateTime values, parsing and applying intervals, and truncating TimeSpan values.
Namespace: OptimaJet.Workflow.Core.Helpers
public static class HelperDateTimeMethods
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
d1DateTimeThe first value to compare.
d2DateTimeThe second value to compare.
Returns
Type
Description
Int320 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
Returns
Type
Description
TimeSpanThe parsed TimeSpan, or TimeSpan.Zero when
value is neither an integer nor a valid fixed-duration interval.Exceptions
Type
Description
ArgumentNullExceptionThrown when
value is null.ArgumentExceptionThrown 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
oldDateTimeDateTimeThe value from which to calculate the interval difference.
intervalStringStringThe interval to apply. A value that can be parsed as an int represents milliseconds.
Returns
Type
Description
TimeSpanThe adjusted value minus
oldDateTime, represented as a TimeSpan.Exceptions
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
dateTimeDateTimeThe value from which to calculate the interval difference.
intervalStringStringThe interval to apply. A value that can be parsed as an int represents milliseconds.
Returns
Type
Description
TimeSpanThe adjusted value minus
dateTime, represented as a TimeSpan.Exceptions
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
dateTimeDateTimeThe value to adjust.
intervalStringStringThe interval to add. A value that can be parsed as an int represents milliseconds.
Returns
Type
Description
DateTimeThe adjusted DateTime.
Exceptions
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
dateTimeDateTimeThe value to adjust.
intervalStringStringThe interval to add. A value that can be parsed as an int represents milliseconds.
Returns
Type
Description
DateTimeThe adjusted DateTime.
Exceptions
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
dateTimeDateTimeThe value to adjust.
intervalStringStringThe interval to apply.
Returns
Type
Description
DateTimeThe adjusted DateTime.
Exceptions
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
dateTimeDateTimeThe value to adjust.
intervalStringStringThe interval to apply.
Returns
Type
Description
DateTimeThe adjusted DateTime.
Exceptions
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.