You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Prowlarr/src/NzbDrone.Common/Extensions/DateTimeExtensions.cs

69 lines
2.1 KiB

using System;
namespace NzbDrone.Common.Extensions
{
public static class DateTimeExtensions
{
public static bool InNextDays(this DateTime dateTime, int days)
{
return InNext(dateTime, new TimeSpan(days, 0, 0, 0));
}
public static bool InLastDays(this DateTime dateTime, int days)
{
return InLast(dateTime, new TimeSpan(days, 0, 0, 0));
}
public static bool InNext(this DateTime dateTime, TimeSpan timeSpan)
{
return dateTime >= DateTime.UtcNow && dateTime <= DateTime.UtcNow.Add(timeSpan);
}
public static bool InLast(this DateTime dateTime, TimeSpan timeSpan)
{
return dateTime >= DateTime.UtcNow.Add(-timeSpan) && dateTime <= DateTime.UtcNow;
}
public static bool Before(this DateTime dateTime, DateTime beforeDateTime)
{
return dateTime <= beforeDateTime;
}
public static bool After(this DateTime dateTime, DateTime afterDateTime)
{
return dateTime >= afterDateTime;
}
public static bool IsValidDate(this string dateTime)
{
DateTime.TryParse(dateTime, out var result);
return !result.Equals(default(DateTime));
}
public static bool IsFutureDate(this string dateTime)
{
DateTime.TryParse(dateTime, out var result);
return !result.Equals(default(DateTime)) && result.After(DateTime.Now);
}
public static bool Between(this DateTime dateTime, DateTime afterDateTime, DateTime beforeDateTime)
{
return dateTime >= afterDateTime && dateTime <= beforeDateTime;
}
public static DateTime EndOfDay(this DateTime date)
{
return new DateTime(date.Year, date.Month, date.Day, 23, 59, 59, 999);
}
public static DateTime StartOfDay(this DateTime date)
{
return new DateTime(date.Year, date.Month, date.Day, 0, 0, 0, 0);
}
public static DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
}
}