Class DateTimeExtensions
- Namespace
- Plugin.BaseTypeExtensions
- Assembly
- Plugin.BaseTypeExtensions.dll
Provides extension methods for DateTime operations, such as range checks and percentage calculations.
public static class DateTimeExtensions
- Inheritance
-
DateTimeExtensions
- Inherited Members
Methods
DateTimeToPercentage(DateTime, DateTime, DateTime)
Converts a DateTime value within a specified range to a percentage. Values outside the range will produce percentages less than 0.0 or greater than 1.0.
public static double DateTimeToPercentage(this DateTime value, DateTime minBound, DateTime maxBound)
Parameters
value
DateTimeThe DateTime value to convert
minBound
DateTimeThe minimum bound of the source range
maxBound
DateTimeThe maximum bound of the source range
Returns
- double
The percentage representation (can be negative or greater than 1.0 for out-of-bounds values)
Exceptions
- ArgumentOutOfRangeException
Thrown when minBound is greater than maxBound
- ArgumentException
Thrown when minBound equals maxBound
PercentageToDateTime(double, DateTime, DateTime)
Converts a percentage (0.0 to 1.0) to a DateTime value within the specified range.
public static DateTime PercentageToDateTime(this double percentage, DateTime minBound, DateTime maxBound)
Parameters
percentage
doubleThe percentage value (0.0 to 1.0)
minBound
DateTimeThe minimum bound of the target range
maxBound
DateTimeThe maximum bound of the target range
Returns
- DateTime
The calculated DateTime value within the specified range
Exceptions
- ArgumentOutOfRangeException
Thrown when minBound is greater than maxBound