@@ -27,6 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
27
using NodaTime ;
28
28
using Point85 . ShiftSharp . Schedule ;
29
29
using System ;
30
+ using System . Collections . Generic ;
30
31
31
32
namespace TestShiftSharp
32
33
{
@@ -36,183 +37,7 @@ public class TestSnippet : BaseTest
36
37
[ TestMethod ]
37
38
public void TestPartial ( )
38
39
{
39
- schedule = new WorkSchedule ( "Working Time1" , "Test working time" ) ;
40
- /*
41
- // shift does not cross midnight
42
- Duration shiftDuration = Duration.FromHours(8);
43
- LocalTime shiftStart = new LocalTime(7, 0, 0);
44
40
45
- Shift shift = schedule.CreateShift("Work Shift1", "Working time shift", shiftStart, shiftDuration);
46
- LocalTime shiftEnd = shift.GetEnd();
47
-
48
- // case #1
49
- Duration time = shift.CalculateWorkingTime(shiftStart.Minus(Period.FromHours(3)), shiftStart.Minus(Period.FromHours(2)));
50
- Assert.IsTrue(time.TotalSeconds == 0);
51
- time = shift.CalculateWorkingTime(shiftStart.Minus(Period.FromHours(3)), shiftStart.Minus(Period.FromHours(3)));
52
- Assert.IsTrue(time.TotalSeconds == 0);
53
-
54
- // case #2
55
- time = shift.CalculateWorkingTime(shiftStart.Minus(Period.FromHours(1)), shiftStart.PlusHours(1));
56
- Assert.IsTrue(time.TotalSeconds == 3600);
57
-
58
- // case #3
59
- time = shift.CalculateWorkingTime(shiftStart.PlusHours(1), shiftStart.PlusHours(2));
60
- Assert.IsTrue(time.TotalSeconds == 3600);
61
-
62
- // case #4
63
- time = shift.CalculateWorkingTime(shiftEnd.Minus(Period.FromHours(1)), shiftEnd.PlusHours(1));
64
- Assert.IsTrue(time.TotalSeconds == 3600);
65
-
66
- // case #5
67
- time = shift.CalculateWorkingTime(shiftEnd.PlusHours(1), shiftEnd.PlusHours(2));
68
- Assert.IsTrue(time.TotalSeconds == 0);
69
- time = shift.CalculateWorkingTime(shiftEnd.PlusHours(1), shiftEnd.PlusHours(1));
70
- Assert.IsTrue(time.TotalSeconds == 0);
71
-
72
- // case #6
73
- time = shift.CalculateWorkingTime(shiftStart.Minus(Period.FromHours(1)), shiftEnd.PlusHours(1));
74
- Assert.IsTrue(time.TotalSeconds == shiftDuration.TotalSeconds);
75
-
76
- // case #7
77
- time = shift.CalculateWorkingTime(shiftStart.PlusHours(1), shiftStart.PlusHours(1));
78
- Assert.IsTrue(time.TotalSeconds == 0);
79
-
80
- // case #8
81
- time = shift.CalculateWorkingTime(shiftStart, shiftEnd);
82
- Assert.IsTrue(time.TotalSeconds == shiftDuration.TotalSeconds);
83
-
84
- // case #9
85
- time = shift.CalculateWorkingTime(shiftStart, shiftStart);
86
- Assert.IsTrue(time.TotalSeconds == 0);
87
-
88
- // case #10
89
- time = shift.CalculateWorkingTime(shiftEnd, shiftEnd);
90
- Assert.IsTrue(time.TotalSeconds == 0);
91
-
92
- // case #11
93
- time = shift.CalculateWorkingTime(shiftStart, shiftStart.PlusSeconds(1));
94
- Assert.IsTrue(time.TotalSeconds == 1);
95
-
96
- // case #12
97
- time = shift.CalculateWorkingTime(shiftEnd.Minus(Period.FromSeconds(1)), shiftEnd);
98
- Assert.IsTrue(time.TotalSeconds == 1);
99
-
100
- // 8 hr shift crossing midnight
101
- shiftStart = new LocalTime(22, 0, 0);
102
-
103
- shift = schedule.CreateShift("Work Shift2", "Working time shift", shiftStart, shiftDuration);
104
- shiftEnd = shift.GetEnd();
105
-
106
- // case #1
107
- time = shift.CalculateWorkingTime(shiftStart.Minus(Period.FromHours(3)), shiftStart.Minus(Period.FromHours(2)), true);
108
- Assert.IsTrue(time.TotalSeconds == 0);
109
- time = shift.CalculateWorkingTime(shiftStart.Minus(Period.FromHours(3)), shiftStart.Minus(Period.FromHours(3)), true);
110
- Assert.IsTrue(time.TotalSeconds == 0);
111
-
112
- // case #2
113
- time = shift.CalculateWorkingTime(shiftStart.Minus(Period.FromHours(1)), shiftStart.PlusHours(1), true);
114
- Assert.IsTrue(time.TotalSeconds == 3600);
115
-
116
- // case #3
117
- time = shift.CalculateWorkingTime(shiftStart.PlusHours(1), shiftStart.PlusHours(2), true);
118
- Assert.IsTrue(time.TotalSeconds == 3600);
119
-
120
- // case #4
121
- time = shift.CalculateWorkingTime(shiftEnd.Minus(Period.FromHours(1)), shiftEnd.PlusHours(1), false);
122
- Assert.IsTrue(time.TotalSeconds == 3600);
123
-
124
- // case #5
125
- time = shift.CalculateWorkingTime(shiftEnd.PlusHours(1), shiftEnd.PlusHours(2), true);
126
- Assert.IsTrue(time.TotalSeconds == 0);
127
- time = shift.CalculateWorkingTime(shiftEnd.PlusHours(1), shiftEnd.PlusHours(1), true);
128
- Assert.IsTrue(time.TotalSeconds == 0);
129
-
130
- // case #6
131
- time = shift.CalculateWorkingTime(shiftStart.Minus(Period.FromHours(1)), shiftEnd.PlusHours(1), true);
132
- Assert.IsTrue(time.TotalSeconds == shiftDuration.TotalSeconds);
133
-
134
- // case #7
135
- time = shift.CalculateWorkingTime(shiftStart.PlusHours(1), shiftStart.PlusHours(1), true);
136
- Assert.IsTrue(time.TotalSeconds == 0);
137
-
138
- // case #8
139
- time = shift.CalculateWorkingTime(shiftStart, shiftEnd, true);
140
- Assert.IsTrue(time.TotalSeconds == shiftDuration.TotalSeconds);
141
-
142
- // case #9
143
- time = shift.CalculateWorkingTime(shiftStart, shiftStart, true);
144
- Assert.IsTrue(time.TotalSeconds == 0);
145
-
146
- // case #10
147
- time = shift.CalculateWorkingTime(shiftEnd, shiftEnd, true);
148
- Assert.IsTrue(time.TotalSeconds == 0);
149
-
150
- // case #11
151
- time = shift.CalculateWorkingTime(shiftStart, shiftStart.PlusSeconds(1), true);
152
- Assert.IsTrue(time.TotalSeconds == 1);
153
-
154
- // case #12
155
- time = shift.CalculateWorkingTime(shiftEnd.Minus(Period.FromSeconds(1)), shiftEnd, false);
156
- Assert.IsTrue(time.TotalSeconds == 1);
157
- */
158
- // 24 hr shift crossing midnight
159
- Duration shiftDuration = Duration . FromHours ( 24 ) ;
160
- LocalTime shiftStart = new LocalTime ( 7 , 0 , 0 ) ;
161
-
162
- Shift shift = schedule . CreateShift ( "Work Shift3" , "Working time shift" , shiftStart , shiftDuration ) ;
163
- LocalTime shiftEnd = shift . GetEnd ( ) ;
164
- /*
165
- // case #1
166
- Duration time = shift.CalculateWorkingTime(shiftStart.Minus(Period.FromHours(3)), shiftStart.Minus(Period.FromHours(2)), false);
167
- Assert.IsTrue(time.TotalSeconds == 3600);
168
- time = shift.CalculateWorkingTime(shiftStart.Minus(Period.FromHours(3)), shiftStart.Minus(Period.FromHours(3)), true);
169
- Assert.IsTrue(time.TotalSeconds == 0);
170
-
171
- // case #2
172
- time = shift.CalculateWorkingTime(shiftStart.Minus(Period.FromHours(1)), shiftStart.PlusHours(1), true);
173
- Assert.IsTrue(time.TotalSeconds == 3600);
174
-
175
- // case #3
176
- time = shift.CalculateWorkingTime(shiftStart.PlusHours(1), shiftStart.PlusHours(2), true);
177
- Assert.IsTrue(time.TotalSeconds == 3600);
178
-
179
- // case #4
180
- time = shift.CalculateWorkingTime(shiftEnd.Minus(Period.FromHours(1)), shiftEnd.PlusHours(1), true);
181
- Assert.IsTrue(time.TotalSeconds == 3600);
182
-
183
- // case #5
184
- time = shift.CalculateWorkingTime(shiftEnd.PlusHours(1), shiftEnd.PlusHours(2), true);
185
- Assert.IsTrue(time.TotalSeconds == 3600);
186
- time = shift.CalculateWorkingTime(shiftEnd.PlusHours(1), shiftEnd.PlusHours(1), true);
187
- Assert.IsTrue(time.TotalSeconds == 0);
188
-
189
- // case #6
190
- time = shift.CalculateWorkingTime(shiftStart.Minus(Period.FromHours(1)), shiftEnd.PlusHours(1), true);
191
- Assert.IsTrue(time.TotalSeconds == 3600);
192
-
193
- // case #7
194
- time = shift.CalculateWorkingTime(shiftStart.PlusHours(1), shiftStart.PlusHours(1), true);
195
- Assert.IsTrue(time.TotalSeconds == 0);
196
- */
197
- // case #8
198
- Duration time = shift . CalculateWorkingTime ( shiftStart , shiftEnd , true ) ;
199
- Assert . IsTrue ( time . TotalSeconds == shiftDuration . TotalSeconds ) ;
200
-
201
- // case #9
202
- time = shift . CalculateWorkingTime ( shiftStart , shiftStart , true ) ;
203
- Assert . IsTrue ( time . TotalSeconds == shiftDuration . TotalSeconds ) ;
204
-
205
- // case #10
206
- time = shift . CalculateWorkingTime ( shiftEnd , shiftEnd , true ) ;
207
- Assert . IsTrue ( time . TotalSeconds == shiftDuration . TotalSeconds ) ;
208
-
209
- // case #11
210
- time = shift . CalculateWorkingTime ( shiftStart , shiftStart . PlusSeconds ( 1 ) , true ) ;
211
- Assert . IsTrue ( time . TotalSeconds == 1 ) ;
212
-
213
- // case #12
214
- time = shift . CalculateWorkingTime ( shiftEnd . Minus ( Period . FromSeconds ( 1 ) ) , shiftEnd , false ) ;
215
- Assert . IsTrue ( time . TotalSeconds == 1 ) ;
216
41
}
217
42
}
218
43
}
0 commit comments