using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DevelopStuff.Extensions
{
public static class IntegerMethods
{
///
/// Returns a N number of seconds ago
///
/// The seconds.
///
public static DateTime SecondsAgo(this int seconds)
{
return DateTime.Now.AddSeconds(-1 * seconds);
}
///
/// Returns a N number of minutes ago
///
/// The seconds.
///
public static DateTime MinutesAgo(this int minutes)
{
return DateTime.Now.AddMinutes(-1 * minutes);
}
///
/// Returns a N number of days ago
///
/// The days.
///
public static DateTime DaysAgo(this int days)
{
return DateTime.Now.AddDays(-1 * days);
}
///
/// Returns a N number of months ago
///
/// The months.
///
public static DateTime MonthsAgo(this int months)
{
return DateTime.Now.AddMonths(-1 * months);
}
///
/// Returns a N number of years ago
///
/// The years.
///
public static DateTime YearsAgo(this int years)
{
return DateTime.Now.AddYears(-1 * years);
}
///
/// Determines whether the integer is within the specified range, inclusive.
///
/// The actual.
/// The lower.
/// The upper.
///
public static bool Within(this int actual, int lower, int upper)
{
return actual.Within(lower, upper, true);
}
///
/// Determines whether the integer is within the specified range, inclusive..
///
/// The actual.
/// The lower.
/// The upper.
/// if set to true [inclusive].
///
public static bool Within(this int actual, int lower, int upper, bool inclusive)
{
if (lower > upper)
{
throw new ArgumentException("The lower bound can't be greater than the upper boundary.", "lower");
}
if (inclusive)
{
return ((actual >= lower) && (actual <= upper));
}
return ((actual > lower) && (actual < upper));
}
}
}