using System; using System.Diagnostics; using NzbDrone.Common.EnsureThat.Resources; using NzbDrone.Common.Extensions; namespace NzbDrone.Common.EnsureThat { public static class EnsureDateTimeExtensions { private static readonly DateTime _minTime = new DateTime(1960, 1, 1); [DebuggerStepThrough] public static Param IsLt(this Param param, DateTime limit) { if (param.Value >= limit) { throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotLt.Inject(param.Value, limit)); } return param; } [DebuggerStepThrough] public static Param IsLte(this Param param, DateTime limit) { if (!(param.Value <= limit)) { throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotLte.Inject(param.Value, limit)); } return param; } [DebuggerStepThrough] public static Param IsGt(this Param param, DateTime limit) { if (param.Value <= limit) { throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotGt.Inject(param.Value, limit)); } return param; } [DebuggerStepThrough] public static Param IsGte(this Param param, DateTime limit) { if (!(param.Value >= limit)) { throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotGte.Inject(param.Value, limit)); } return param; } [DebuggerStepThrough] public static Param IsInRange(this Param param, DateTime min, DateTime max) { if (param.Value < min) { throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotInRange_ToLow.Inject(param.Value, min)); } if (param.Value > max) { throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotInRange_ToHigh.Inject(param.Value, max)); } return param; } [DebuggerStepThrough] public static Param IsUtc(this Param param) { if (param.Value.Kind != DateTimeKind.Utc) { throw ExceptionFactory.CreateForParamValidation(param.Name, "Excepted time to be in UTC but was [{0}]".Inject(param.Value.Kind)); } return param; } [DebuggerStepThrough] public static Param IsValid(this Param param) { return IsGt(param, _minTime); } } }