using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
namespace EasyDevCore.Common
{
///
/// DateTime extension helper
///
public static class DateTimeExtensions
{
///
/// Parses by format.
///
/// The input.
/// The format.
///
public static DateTime ParseByFormat(this DateTime input, string format)
{
return DateTime.ParseExact(input.ToString(format), format, System.Globalization.CultureInfo.InvariantCulture);
}
///
/// Determines whether this instance is expired.
///
/// The input.
///
/// true if the specified input is expired; otherwise, false.
///
public static bool IsExpired(this DateTime? input)
{
return input != null && input.Value > DateTime.Now;
}
///
/// Determines whether this instance is expired.
///
/// The input.
///
/// true if the specified input is expired; otherwise, false.
///
public static bool IsExpired(this DateTime input)
{
return input > DateTime.Now;
}
///
/// Gets the week of month.
///
/// The time.
///
public static int GetWeekOfMonth(this DateTime time)
{
DateTime first = new DateTime(time.Year, time.Month, 1);
return time.GetWeekOfYear() - first.GetWeekOfYear() + 1;
}
///
/// Gets the week of year.
///
/// The time.
///
public static int GetWeekOfYear(this DateTime time)
{
return new GregorianCalendar().GetWeekOfYear(time, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
}
}
}