WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
DateTimeExtensions.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Extensions;
6 
7 
8 public static class DateTimeExtensions
9 {
10  public static DateTime Limit(this DateTime DateToLimit, DateTime MinDate, DateTime MaxDate)
11  {
12  if (DateToLimit < MinDate) return MinDate;
13  if (DateToLimit > MaxDate) return MaxDate;
14  return DateToLimit;
15  }
16 
17  public static DateTime? Limit(this DateTime? DateToLimit, DateTime MinDate, DateTime MaxDate)
18  {
19  if (!DateToLimit.HasValue) return null;
20  if (DateToLimit < MinDate) return MinDate;
21  if (DateToLimit > MaxDate) return MaxDate;
22  return DateToLimit;
23  }
24 
25 
26  public static bool IsBetween(this DateTime DateToCheck, DateTime MinDate, DateTime MaxDate)
27  {
28  return DateToCheck >= MinDate && DateToCheck <= MaxDate;
29  }
30 
31 
32  public static bool IsBetween(this DateTime? DateToCheck, DateTime MinDate, DateTime MaxDate)
33  {
34  if (!DateToCheck.HasValue) return false;
35  return DateToCheck.Value >= MinDate && DateToCheck.Value <= MaxDate;
36  }
37 
38  public static DateTime FirstDayOfMonth(this DateTime DateTime)
39  {
40  return new DateTime(DateTime.Year, DateTime.Month, 1);
41 
42  }
43 
44  public static DateTime LastDayOfMonth(this DateTime DateTime)
45  {
46  return new DateTime(DateTime.Year, DateTime.Month, DateTime.DaysInMonth(DateTime.Year, DateTime.Month));
47 
48  }
49 
50 
51 
52 }