1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 04:55:42 +00:00

Add time-related extension methods

This commit is contained in:
Oliver Booth 2022-04-21 20:54:17 +01:00
parent 8683bd79fa
commit a1722e4374
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
13 changed files with 1094 additions and 0 deletions

View File

@ -0,0 +1,87 @@
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="byte" />.
/// </summary>
public static class ByteExtensions
{
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of ticks.
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Ticks(this byte value)
{
return TimeSpan.FromTicks(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of milliseconds.
/// </summary>
/// <param name="value">The duration, in milliseconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Milliseconds(this byte value)
{
return TimeSpan.FromMilliseconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of seconds.
/// </summary>
/// <param name="value">The duration, in seconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Seconds(this byte value)
{
return TimeSpan.FromSeconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of minutes.
/// </summary>
/// <param name="value">The duration, in minutes.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Minutes(this byte value)
{
return TimeSpan.FromMinutes(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of hours.
/// </summary>
/// <param name="value">The duration, in hours.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Hours(this byte value)
{
return TimeSpan.FromHours(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of days.
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Days(this byte value)
{
return TimeSpan.FromDays(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of weeks.
/// </summary>
/// <param name="value">The duration, in weeks.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
public static TimeSpan Weeks(this byte value)
{
return TimeSpan.FromDays(value * 7);
}
}

View File

@ -0,0 +1,77 @@
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="decimal" />.
/// </summary>
public static class DecimalExtensions
{
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of milliseconds.
/// </summary>
/// <param name="value">The duration, in milliseconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Milliseconds(this decimal value)
{
return TimeSpan.FromMilliseconds((double)value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of seconds.
/// </summary>
/// <param name="value">The duration, in seconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Seconds(this decimal value)
{
return TimeSpan.FromSeconds((double)value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of minutes.
/// </summary>
/// <param name="value">The duration, in minutes.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Minutes(this decimal value)
{
return TimeSpan.FromMinutes((double)value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of hours.
/// </summary>
/// <param name="value">The duration, in hours.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Hours(this decimal value)
{
return TimeSpan.FromHours((double)value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of days.
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Days(this decimal value)
{
return TimeSpan.FromDays((double)value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of weeks.
/// </summary>
/// <param name="value">The duration, in weeks.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
public static TimeSpan Weeks(this decimal value)
{
return TimeSpan.FromDays((double)value * 7);
}
}

View File

@ -0,0 +1,77 @@
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="double" />.
/// </summary>
public static class DoubleExtensions
{
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of milliseconds.
/// </summary>
/// <param name="value">The duration, in milliseconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Milliseconds(this double value)
{
return TimeSpan.FromMilliseconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of seconds.
/// </summary>
/// <param name="value">The duration, in seconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Seconds(this double value)
{
return TimeSpan.FromSeconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of minutes.
/// </summary>
/// <param name="value">The duration, in minutes.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Minutes(this double value)
{
return TimeSpan.FromMinutes(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of hours.
/// </summary>
/// <param name="value">The duration, in hours.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Hours(this double value)
{
return TimeSpan.FromHours(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of days.
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Days(this double value)
{
return TimeSpan.FromDays(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of weeks.
/// </summary>
/// <param name="value">The duration, in weeks.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
public static TimeSpan Weeks(this double value)
{
return TimeSpan.FromDays(value * 7);
}
}

View File

@ -0,0 +1,77 @@
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="Half" />.
/// </summary>
public static class HalfExtensions
{
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of milliseconds.
/// </summary>
/// <param name="value">The duration, in milliseconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Milliseconds(this Half value)
{
return TimeSpan.FromMilliseconds((float)value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of seconds.
/// </summary>
/// <param name="value">The duration, in seconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Seconds(this Half value)
{
return TimeSpan.FromSeconds((float)value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of minutes.
/// </summary>
/// <param name="value">The duration, in minutes.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Minutes(this Half value)
{
return TimeSpan.FromMinutes((float)value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of hours.
/// </summary>
/// <param name="value">The duration, in hours.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Hours(this Half value)
{
return TimeSpan.FromHours((float)value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of days.
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Days(this Half value)
{
return TimeSpan.FromDays((float)value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of weeks.
/// </summary>
/// <param name="value">The duration, in weeks.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
public static TimeSpan Weeks(this Half value)
{
return TimeSpan.FromDays((float)value * 7);
}
}

View File

@ -0,0 +1,87 @@
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="short" />.
/// </summary>
public static class Int16Extensions
{
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of ticks.
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Ticks(this short value)
{
return TimeSpan.FromTicks(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of milliseconds.
/// </summary>
/// <param name="value">The duration, in milliseconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Milliseconds(this short value)
{
return TimeSpan.FromMilliseconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of seconds.
/// </summary>
/// <param name="value">The duration, in seconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Seconds(this short value)
{
return TimeSpan.FromSeconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of minutes.
/// </summary>
/// <param name="value">The duration, in minutes.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Minutes(this short value)
{
return TimeSpan.FromMinutes(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of hours.
/// </summary>
/// <param name="value">The duration, in hours.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Hours(this short value)
{
return TimeSpan.FromHours(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of days.
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Days(this short value)
{
return TimeSpan.FromDays(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of weeks.
/// </summary>
/// <param name="value">The duration, in weeks.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
public static TimeSpan Weeks(this short value)
{
return TimeSpan.FromDays(value * 7);
}
}

View File

@ -0,0 +1,87 @@
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="int" />.
/// </summary>
public static class Int32Extensions
{
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of ticks.
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Ticks(this int value)
{
return TimeSpan.FromTicks(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of milliseconds.
/// </summary>
/// <param name="value">The duration, in milliseconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Milliseconds(this int value)
{
return TimeSpan.FromMilliseconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of seconds.
/// </summary>
/// <param name="value">The duration, in seconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Seconds(this int value)
{
return TimeSpan.FromSeconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of minutes.
/// </summary>
/// <param name="value">The duration, in minutes.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Minutes(this int value)
{
return TimeSpan.FromMinutes(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of hours.
/// </summary>
/// <param name="value">The duration, in hours.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Hours(this int value)
{
return TimeSpan.FromHours(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of days.
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Days(this int value)
{
return TimeSpan.FromDays(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of weeks.
/// </summary>
/// <param name="value">The duration, in weeks.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
public static TimeSpan Weeks(this int value)
{
return TimeSpan.FromDays(value * 7);
}
}

View File

@ -0,0 +1,87 @@
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="long" />.
/// </summary>
public static class Int64Extensions
{
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of ticks.
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Ticks(this long value)
{
return TimeSpan.FromTicks(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of milliseconds.
/// </summary>
/// <param name="value">The duration, in milliseconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Milliseconds(this long value)
{
return TimeSpan.FromMilliseconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of seconds.
/// </summary>
/// <param name="value">The duration, in seconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Seconds(this long value)
{
return TimeSpan.FromSeconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of minutes.
/// </summary>
/// <param name="value">The duration, in minutes.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Minutes(this long value)
{
return TimeSpan.FromMinutes(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of hours.
/// </summary>
/// <param name="value">The duration, in hours.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Hours(this long value)
{
return TimeSpan.FromHours(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of days.
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Days(this long value)
{
return TimeSpan.FromDays(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of weeks.
/// </summary>
/// <param name="value">The duration, in weeks.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
public static TimeSpan Weeks(this long value)
{
return TimeSpan.FromDays(value * 7);
}
}

View File

@ -0,0 +1,88 @@
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="sbyte" />.
/// </summary>
[CLSCompliant(false)]
public static class SByteExtensions
{
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of ticks.
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Ticks(this sbyte value)
{
return TimeSpan.FromTicks(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of milliseconds.
/// </summary>
/// <param name="value">The duration, in milliseconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Milliseconds(this sbyte value)
{
return TimeSpan.FromMilliseconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of seconds.
/// </summary>
/// <param name="value">The duration, in seconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Seconds(this sbyte value)
{
return TimeSpan.FromSeconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of minutes.
/// </summary>
/// <param name="value">The duration, in minutes.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Minutes(this sbyte value)
{
return TimeSpan.FromMinutes(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of hours.
/// </summary>
/// <param name="value">The duration, in hours.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Hours(this sbyte value)
{
return TimeSpan.FromHours(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of days.
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Days(this sbyte value)
{
return TimeSpan.FromDays(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of weeks.
/// </summary>
/// <param name="value">The duration, in weeks.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
public static TimeSpan Weeks(this sbyte value)
{
return TimeSpan.FromDays(value * 7);
}
}

View File

@ -0,0 +1,77 @@
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="float" />.
/// </summary>
public static class SingleExtensions
{
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of milliseconds.
/// </summary>
/// <param name="value">The duration, in milliseconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Milliseconds(this float value)
{
return TimeSpan.FromMilliseconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of seconds.
/// </summary>
/// <param name="value">The duration, in seconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Seconds(this float value)
{
return TimeSpan.FromSeconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of minutes.
/// </summary>
/// <param name="value">The duration, in minutes.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Minutes(this float value)
{
return TimeSpan.FromMinutes(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of hours.
/// </summary>
/// <param name="value">The duration, in hours.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Hours(this float value)
{
return TimeSpan.FromHours(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of days.
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Days(this float value)
{
return TimeSpan.FromDays(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of weeks.
/// </summary>
/// <param name="value">The duration, in weeks.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
public static TimeSpan Weeks(this float value)
{
return TimeSpan.FromDays(value * 7);
}
}

View File

@ -0,0 +1,31 @@
namespace X10D.Time;
/// <summary>
/// Extension methods for <see cref="TimeSpan" />.
/// </summary>
public static class TimeSpanExtensions
{
/// <summary>
/// Returns a <see cref="DateTime" /> that is a specified duration in the past relative to the current time.
/// </summary>
/// <param name="value">The <see cref="TimeSpan" /> whose duration to subtract.</param>
/// <returns>
/// A <see cref="DateTime" /> that is a duration of <paramref name="value" /> in the past relative to the current time.
/// </returns>
public static DateTime Ago(this TimeSpan value)
{
return DateTime.Now.Subtract(value);
}
/// <summary>
/// Returns a <see cref="DateTime" /> that is a specified duration in the future relative to the current time.
/// </summary>
/// <param name="value">The <see cref="TimeSpan" /> whose duration to add.</param>
/// <returns>
/// A <see cref="DateTime" /> that is a duration of <paramref name="value" /> in the future relative to the current time.
/// </returns>
public static DateTime FromNow(this TimeSpan value)
{
return DateTime.Now.Add(value);
}
}

View File

@ -0,0 +1,88 @@
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="ushort" />.
/// </summary>
[CLSCompliant(false)]
public static class UInt16Extensions
{
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of ticks.
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Ticks(this ushort value)
{
return TimeSpan.FromTicks(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of milliseconds.
/// </summary>
/// <param name="value">The duration, in milliseconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Milliseconds(this ushort value)
{
return TimeSpan.FromMilliseconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of seconds.
/// </summary>
/// <param name="value">The duration, in seconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Seconds(this ushort value)
{
return TimeSpan.FromSeconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of minutes.
/// </summary>
/// <param name="value">The duration, in minutes.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Minutes(this ushort value)
{
return TimeSpan.FromMinutes(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of hours.
/// </summary>
/// <param name="value">The duration, in hours.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Hours(this ushort value)
{
return TimeSpan.FromHours(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of days.
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Days(this ushort value)
{
return TimeSpan.FromDays(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of weeks.
/// </summary>
/// <param name="value">The duration, in weeks.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
public static TimeSpan Weeks(this ushort value)
{
return TimeSpan.FromDays(value * 7);
}
}

View File

@ -0,0 +1,88 @@
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="uint" />.
/// </summary>
[CLSCompliant(false)]
public static class UInt32Extensions
{
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of ticks.
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Ticks(this uint value)
{
return TimeSpan.FromTicks(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of milliseconds.
/// </summary>
/// <param name="value">The duration, in milliseconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Milliseconds(this uint value)
{
return TimeSpan.FromMilliseconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of seconds.
/// </summary>
/// <param name="value">The duration, in seconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Seconds(this uint value)
{
return TimeSpan.FromSeconds(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of minutes.
/// </summary>
/// <param name="value">The duration, in minutes.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Minutes(this uint value)
{
return TimeSpan.FromMinutes(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of hours.
/// </summary>
/// <param name="value">The duration, in hours.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Hours(this uint value)
{
return TimeSpan.FromHours(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of days.
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Days(this uint value)
{
return TimeSpan.FromDays(value);
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of weeks.
/// </summary>
/// <param name="value">The duration, in weeks.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
public static TimeSpan Weeks(this uint value)
{
return TimeSpan.FromDays(value * 7);
}
}

View File

@ -0,0 +1,143 @@
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="ulong" />.
/// </summary>
[CLSCompliant(false)]
public static class UInt64Extensions
{
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of ticks.
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Ticks(this ulong value)
{
long remainder = 0;
if (value > long.MaxValue)
{
remainder = (long)(value - long.MaxValue);
value -= long.MaxValue;
}
return TimeSpan.FromTicks((long)value).Add(TimeSpan.FromTicks(remainder));
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of milliseconds.
/// </summary>
/// <param name="value">The duration, in milliseconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Milliseconds(this ulong value)
{
long remainder = 0;
if (value > long.MaxValue)
{
remainder = (long)(value - long.MaxValue);
value -= long.MaxValue;
}
return TimeSpan.FromMilliseconds((long)value).Add(TimeSpan.FromMilliseconds(remainder));
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of seconds.
/// </summary>
/// <param name="value">The duration, in seconds.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Seconds(this ulong value)
{
long remainder = 0;
if (value > long.MaxValue)
{
remainder = (long)(value - long.MaxValue);
value -= long.MaxValue;
}
return TimeSpan.FromSeconds((long)value).Add(TimeSpan.FromSeconds(remainder));
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of minutes.
/// </summary>
/// <param name="value">The duration, in minutes.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Minutes(this ulong value)
{
long remainder = 0;
if (value > long.MaxValue)
{
remainder = (long)(value - long.MaxValue);
value -= long.MaxValue;
}
return TimeSpan.FromMinutes((long)value).Add(TimeSpan.FromMinutes(remainder));
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of hours.
/// </summary>
/// <param name="value">The duration, in hours.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
public static TimeSpan Hours(this ulong value)
{
long remainder = 0;
if (value > long.MaxValue)
{
remainder = (long)(value - long.MaxValue);
value -= long.MaxValue;
}
return TimeSpan.FromHours((long)value).Add(TimeSpan.FromHours(remainder));
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of days.
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
public static TimeSpan Days(this ulong value)
{
long remainder = 0;
if (value > long.MaxValue)
{
remainder = (long)(value - long.MaxValue);
value -= long.MaxValue;
}
return TimeSpan.FromDays((long)value).Add(TimeSpan.FromDays(remainder));
}
/// <summary>
/// Returns a <see cref="TimeSpan" /> that represents this value as the number of weeks.
/// </summary>
/// <param name="value">The duration, in weeks.</param>
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
public static TimeSpan Weeks(this ulong value)
{
long remainder = 0;
if (value > long.MaxValue)
{
remainder = (long)(value - long.MaxValue);
value -= long.MaxValue;
}
return TimeSpan.FromDays((long)value * 7).Add(TimeSpan.FromDays(remainder * 7));
}
}