blob: 6ca47abe578812b73b006fa75bec3cea63911fca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
namespace domain
{
using System;
public class Month
{
int year;
int month;
public Month(int year, int month)
{
this.year = year;
this.month = month;
}
public bool Equals(Month other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return other.year == year && other.month == month;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof (Month)) return false;
return Equals((Month) obj);
}
public override int GetHashCode()
{
unchecked
{
return (year*397) ^ month;
}
}
public Month Plus(int months)
{
var newMonth = new DateTime(year, month, 01).AddMonths(months);
return new Month(newMonth.Year, newMonth.Month);
}
public override string ToString()
{
return string.Format("{0} {1}", year, month);
}
}
}
|