1: using System;
2:
3: namespace ConsoleApplication1
4: {
5: class Program
6: {
7: static void Main(string[] args)
8: {
9: var somedate = new DateTime(2010, 1, 10);
10: var otherDate = new DateTime(2010, 1, 31);
11:
12: System.Diagnostics.Debug.Assert(somedate.IsBefore(otherDate));
13: System.Diagnostics.Debug.Assert(otherDate.IsBefore(somedate) == false);
14:
15: System.Diagnostics.Debug.Assert(Dates.Is(otherDate).OnOrAfter(somedate));
16: System.Diagnostics.Debug.Assert(Dates.Is(somedate).OnOrAfter(otherDate) == false);
17:
18: System.Diagnostics.Debug.Assert(Dates.Is(somedate).OnOrBefore(otherDate));
19: System.Diagnostics.Debug.Assert(Dates.Is(otherDate).OnOrBefore(somedate) == false);
20:
21: System.Diagnostics.Debug.Assert(Dates.Is(otherDate).On(otherDate));
22: System.Diagnostics.Debug.Assert(Dates.Is(otherDate).On(somedate) == false);
23:
24:
25:
26: }
27: }
28:
29: public static class Dates
30: {
31: public static bool IsBefore(this DateTime firstDateTime, DateTime otherDate)
32: {
33: return (firstDateTime <= otherDate) ? true : false;
34: }
35:
36: public static bool IsAfter(this DateTime firstDateTime, DateTime otherDate)
37: {
38: return (firstDateTime >= otherDate) ? true : false;
39: }
40:
41: public static DatesBuilder Is(DateTime firstDateTime)
42: {
43: return new DatesBuilder(firstDateTime);
44: }
45:
46: public class DatesBuilder
47: {
48: private DateTime _firstDateTime;
49:
50: public DatesBuilder(DateTime firstDateTime)
51: {
52: this._firstDateTime = firstDateTime;
53: }
54:
55: public bool OnOrAfter(DateTime otherDate)
56: {
57: return !_firstDateTime.IsBefore(otherDate);
58: }
59:
60: public bool OnOrBefore(DateTime otherDate)
61: {
62: return !_firstDateTime.IsAfter(otherDate);
63: }
64:
65: public bool On(DateTime otherDate)
66: {
67: return _firstDateTime.Equals(otherDate);
68: }
69: }
70: }
71: }