forked from Giannoudis/TimePeriodLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinute.cs
114 lines (95 loc) · 3.55 KB
/
Minute.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
// -- FILE ------------------------------------------------------------------
// name : Minute.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 Minute : MinuteTimeRange
{
// ----------------------------------------------------------------------
public Minute() :
this( new TimeCalendar() )
{
} // Minute
// ----------------------------------------------------------------------
public Minute( ITimeCalendar calendar ) :
this( ClockProxy.Clock.Now, calendar )
{
} // Minute
// ----------------------------------------------------------------------
public Minute( DateTime moment ) :
this( moment, new TimeCalendar() )
{
} // Minute
// ----------------------------------------------------------------------
public Minute( DateTime moment, ITimeCalendar calendar ) :
this( calendar.GetYear( moment ), calendar.GetMonth( moment ), calendar.GetDayOfMonth( moment ),
calendar.GetHour( moment ), calendar.GetMinute( moment ), calendar )
{
} // Minute
// ----------------------------------------------------------------------
public Minute( int year, int month, int day, int hour, int minute ) :
this( year, month, day, hour, minute, new TimeCalendar() )
{
} // Minute
// ----------------------------------------------------------------------
public Minute( int year, int month, int day, int hour, int minute, ITimeCalendar calendar ) :
base( year, month, day, hour, minute, 1, calendar )
{
} // Minute
// ----------------------------------------------------------------------
public int Year
{
get { return StartYear; }
} // Year
// ----------------------------------------------------------------------
public int Month
{
get { return StartMonth; }
} // Month
// ----------------------------------------------------------------------
public int Day
{
get { return StartDay; }
} // Day
// ----------------------------------------------------------------------
public int Hour
{
get { return StartHour; }
} // Hour
// ----------------------------------------------------------------------
public int MinuteValue
{
get { return StartMinute; }
} // MinuteValue
// ----------------------------------------------------------------------
public Minute GetPreviousMinute()
{
return AddMinutes( -1 );
} // GetPreviousMinute
// ----------------------------------------------------------------------
public Minute GetNextMinute()
{
return AddMinutes( 1 );
} // GetNextMinute
// ----------------------------------------------------------------------
public Minute AddMinutes( int minutes )
{
DateTime startMinute = new DateTime( StartYear, StartMonth, StartDay, StartHour, StartMinute, 0 );
return new Minute( startMinute.AddMinutes( minutes ), Calendar );
} // AddMinutes
// ----------------------------------------------------------------------
protected override string Format( ITimeFormatter formatter )
{
return formatter.GetCalendarPeriod( formatter.GetShortDate( Start ),
formatter.GetShortTime( Start ), formatter.GetShortTime( End ), Duration );
} // Format
} // class Minute
} // namespace Itenso.TimePeriod
// -- EOF -------------------------------------------------------------------