main
 1using System;
 2
 3namespace Gorilla.Commons.Utility
 4{
 5    public class Year
 6    {
 7        readonly int the_underlying_year;
 8
 9        public Year(int year) : this(new DateTime(year, 01, 01))
10        {
11        }
12
13        public Year(DateTime date)
14        {
15            the_underlying_year = date.Year;
16        }
17
18        static public implicit operator Year(int year)
19        {
20            return new Year(year);
21        }
22
23        public bool Equals(Year obj)
24        {
25            if (ReferenceEquals(null, obj)) return false;
26            if (ReferenceEquals(this, obj)) return true;
27            return obj.the_underlying_year == the_underlying_year;
28        }
29
30        public override bool Equals(object obj)
31        {
32            if (ReferenceEquals(null, obj)) return false;
33            if (ReferenceEquals(this, obj)) return true;
34            if (obj.GetType() != typeof (Year)) return false;
35            return Equals((Year) obj);
36        }
37
38        public override int GetHashCode()
39        {
40            return the_underlying_year;
41        }
42
43        public bool represents(DateTime time)
44        {
45            return time.Year.Equals(the_underlying_year);
46        }
47
48        public override string ToString()
49        {
50            return the_underlying_year.ToString();
51        }
52    }
53}