forked from Giannoudis/TimePeriodLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Month.cs
119 lines (99 loc) · 3.59 KB
/
Month.cs
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// -- FILE ------------------------------------------------------------------
// name : Month.cs
// project : Itenso Time Period
// created : Jani Giannoudis - 2011.02.18
// language : C# 4.0
// environment: .NET 2.0
// copyright : (c) 2011-2012 by Itenso GmbH, Switzerland
// --------------------------------------------------------------------------
using System;
namespace Itenso.TimePeriod
{
// ------------------------------------------------------------------------
public sealed class Month : MonthTimeRange
{
// ----------------------------------------------------------------------
public Month() :
this( new TimeCalendar() )
{
} // Month
// ----------------------------------------------------------------------
public Month( ITimeCalendar calendar ) :
this( ClockProxy.Clock.Now, calendar )
{
} // Month
// ----------------------------------------------------------------------
public Month( DateTime moment ) :
this( moment, new TimeCalendar() )
{
} // Month
// ----------------------------------------------------------------------
public Month( DateTime moment, ITimeCalendar calendar ) :
this( calendar.GetYear( moment ), (YearMonth)calendar.GetMonth( moment ), calendar )
{
} // Month
// ----------------------------------------------------------------------
public Month( int year, YearMonth yearMonth ) :
this( year, yearMonth, new TimeCalendar() )
{
} // Month
// ----------------------------------------------------------------------
public Month( int year, YearMonth yearMonth, ITimeCalendar calendar ) :
base( year, yearMonth, 1, calendar )
{
} // Month
// ----------------------------------------------------------------------
public int Year
{
get { return StartYear; }
} // Year
// ----------------------------------------------------------------------
public YearMonth YearMonth
{
get { return StartMonth; }
} // YearMonth
// ----------------------------------------------------------------------
public int MonthValue
{
get { return (int)StartMonth; }
} // MonthValue
// ----------------------------------------------------------------------
public string MonthName
{
get { return StartMonthName; }
} // MonthName
// ----------------------------------------------------------------------
public string MonthOfYearName
{
get { return StartMonthOfYearName; }
} // MonthOfYearName
// ----------------------------------------------------------------------
public int DaysInMonth
{
get { return TimeTool.GetDaysInMonth( StartYear, (int)StartMonth ); }
} // DaysInMonth
// ----------------------------------------------------------------------
public Month GetPreviousMonth()
{
return AddMonths( -1 );
} // GetPreviousMonth
// ----------------------------------------------------------------------
public Month GetNextMonth()
{
return AddMonths( 1 );
} // GetNextMonth
// ----------------------------------------------------------------------
public Month AddMonths( int months )
{
DateTime startDate = new DateTime( StartYear, (int)StartMonth, 1 );
return new Month( startDate.AddMonths( months ), Calendar );
} // AddMonths
// ----------------------------------------------------------------------
protected override string Format( ITimeFormatter formatter )
{
return formatter.GetCalendarPeriod( MonthOfYearName,
formatter.GetShortDate( Start ), formatter.GetShortDate( End ), Duration );
} // Format
} // class Month
} // namespace Itenso.TimePeriod
// -- EOF -------------------------------------------------------------------