Skip to content

Commit 611a958

Browse files
committed
wip
1 parent 0f76316 commit 611a958

8 files changed

Lines changed: 104 additions & 249 deletions

File tree

ShiftSharp/Rotation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public Duration GetWorkingTime()
152152
{
153153
if (period.IsWorkingPeriod())
154154
{
155-
sum = sum.Plus(period.GetDuration());
155+
sum = sum.Plus(period.Duration);
156156
}
157157
}
158158
return sum;

ShiftSharp/Shift.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public Duration CalculateWorkingTime(LocalTime from, LocalTime to)
144144
*/
145145
public bool SpansMidnight()
146146
{
147-
int startSecond = ToRoundedSecond(GetStart());
147+
int startSecond = ToRoundedSecond(StartTime);
148148
int endSecond = ToRoundedSecond(GetEnd());
149149
return endSecond <= startSecond ? true : false;
150150
}
@@ -167,15 +167,15 @@ public Duration CalculateWorkingTime(LocalTime from, LocalTime to, bool beforeMi
167167
{
168168
Duration duration = Duration.Zero;
169169

170-
int startSecond = ToRoundedSecond(GetStart());
170+
int startSecond = ToRoundedSecond(StartTime);
171171
int endSecond = ToRoundedSecond(GetEnd());
172172
int fromSecond = ToRoundedSecond(from);
173173
int toSecond = ToRoundedSecond(to);
174174

175175
int delta = toSecond - fromSecond;
176176

177177
// check for 24 hour shift
178-
if (delta == 0 && fromSecond == startSecond && GetDuration().TotalHours == 24)
178+
if (delta == 0 && fromSecond == startSecond && Duration.TotalHours == 24)
179179
{
180180
delta = 86400;
181181
}
@@ -238,7 +238,7 @@ public bool IsInShift(LocalTime time)
238238
{
239239
bool answer = false;
240240

241-
LocalTime start = GetStart();
241+
LocalTime start = StartTime;
242242
LocalTime end = GetEnd();
243243

244244
int onStart = time.CompareTo(start);
@@ -287,7 +287,7 @@ public Duration CalculateBreakTime()
287287

288288
foreach (Break b in breaks)
289289
{
290-
sum = sum.Plus(b.GetDuration());
290+
sum = sum.Plus(b.Duration);
291291
}
292292

293293
return sum;

ShiftSharp/ShiftInstance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ internal ShiftInstance(Shift shift, LocalDateTime startDateTime, Team team)
5555
*/
5656
public LocalDateTime GetEndTime()
5757
{
58-
Duration duration = Shift.GetDuration();
58+
Duration duration = Shift.Duration;
5959
return StartDateTime.PlusSeconds((long)duration.TotalSeconds);
6060
}
6161

ShiftSharp/Team.cs

Lines changed: 18 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ namespace Point85.ShiftSharp.Schedule
3333
public class Team : Named, IComparable<Team>
3434
{
3535
// owning work schedule
36-
private WorkSchedule workSchedule;
36+
public WorkSchedule WorkSchedule { get; set; }
3737

3838
// reference date for starting the rotations
39-
private LocalDate rotationStart;
39+
public LocalDate RotationStart { get; set; }
4040

4141
// shift rotation days
42-
private Rotation rotation;
42+
public Rotation Rotation { get; set; }
4343

4444
/**
4545
* Default constructor
@@ -50,68 +50,8 @@ public Team() : base()
5050

5151
internal Team(string name, string description, Rotation rotation, LocalDate rotationStart) : base(name, description)
5252
{
53-
this.rotation = rotation;
54-
this.SetRotationStart(rotationStart);
55-
}
56-
57-
/**
58-
* Get rotation start
59-
*
60-
* @return Rotation start date
61-
*/
62-
public LocalDate GetRotationStart()
63-
{
64-
return rotationStart;
65-
}
66-
67-
/**
68-
* Get rotation start
69-
*
70-
* @param rotationStart
71-
* Starting date of rotation
72-
*/
73-
public void SetRotationStart(LocalDate rotationStart)
74-
{
75-
this.rotationStart = rotationStart;
76-
}
77-
78-
/*
79-
private long GetDayFrom()
80-
{
81-
LocalDate localDate;
82-
int eraYear = localDate.YearOfEra;
83-
//NodaTime.Calendars.Era era = rotationStart.Era;
84-
//LocalDateTime now;
85-
Instant unixStart = Instant.FromUnixTimeSeconds(0);
86-
Instant.FromUtc(2017, 10, 23, 0, 0, 0);
87-
Instant now = SystemClock.Instance.GetCurrentInstant();
88-
89-
Instant unixEpoch = NodaConstants.UnixEpoch;
90-
Duration duration = now.Minus(unixEpoch);
91-
92-
return rotationStart.toEpochDay();
93-
}
94-
*/
95-
96-
/**
97-
* Get the shift rotation for this team
98-
*
99-
* @return {@link Rotation}
100-
*/
101-
public Rotation GetRotation()
102-
{
103-
return rotation;
104-
}
105-
106-
/**
107-
* Set the shift rotation for this team
108-
*
109-
* @param rotation
110-
* {@link Rotation}
111-
*/
112-
public void SetRotation(Rotation rotation)
113-
{
114-
this.rotation = rotation;
53+
this.Rotation = rotation;
54+
this.RotationStart = rotationStart;
11555
}
11656

11757
/**
@@ -123,7 +63,7 @@ public void SetRotation(Rotation rotation)
12363
*/
12464
public Duration GetRotationDuration()
12565
{
126-
return GetRotation().GetDuration();
66+
return Rotation.GetDuration();
12767
}
12868

12969
/**
@@ -136,7 +76,7 @@ public Duration GetRotationDuration()
13676
*/
13777
public float GetPercentageWorked()
13878
{
139-
double ratio = GetRotation().GetWorkingTime().TotalSeconds / GetRotationDuration().TotalSeconds;
79+
double ratio = Rotation.GetWorkingTime().TotalSeconds / GetRotationDuration().TotalSeconds;
14080
return (float)ratio * 100.0f;
14181
}
14282

@@ -147,8 +87,8 @@ public float GetPercentageWorked()
14787
*/
14888
public Duration GetHoursWorkedPerWeek()
14989
{
150-
double days = GetRotation().GetDuration().TotalDays;
151-
double secPerWeek = GetRotation().GetWorkingTime().TotalSeconds * (7.0f / days);
90+
double days = Rotation.GetDuration().TotalDays;
91+
double secPerWeek = Rotation.GetWorkingTime().TotalSeconds * (7.0f / days);
15292
return Duration.FromSeconds(secPerWeek);
15393
}
15494

@@ -164,15 +104,15 @@ public Duration GetHoursWorkedPerWeek()
164104
public int GetDayInRotation(LocalDate date)
165105
{
166106
// calculate total number of days from start of rotation
167-
long deltaDays = TimePeriod.DeltaDays(rotationStart, date);
107+
long deltaDays = TimePeriod.DeltaDays(RotationStart, date);
168108

169109
if (deltaDays < 0)
170110
{
171-
string msg = string.Format(WorkSchedule.GetMessage("end.earlier.than.start"), rotationStart, date);
111+
string msg = string.Format(WorkSchedule.GetMessage("end.earlier.than.start"), RotationStart, date);
172112
throw new Exception(msg);
173113
}
174114

175-
int dayInRotation = (int)(deltaDays % GetRotation().GetDuration().Days) + 1;
115+
int dayInRotation = (int)(deltaDays % Rotation.GetDuration().Days) + 1;
176116
return dayInRotation;
177117
}
178118

@@ -189,15 +129,15 @@ public ShiftInstance GetShiftInstanceForDay(LocalDate day)
189129
{
190130
ShiftInstance instance = null;
191131

192-
Rotation shiftRotation = GetRotation();
132+
Rotation shiftRotation = Rotation;
193133
int dayInRotation = GetDayInRotation(day);
194134

195135
// shift or off shift
196136
TimePeriod period = shiftRotation.GetPeriods()[dayInRotation - 1];
197137

198138
if (period.IsWorkingPeriod())
199139
{
200-
LocalDateTime startDateTime = day.At(period.GetStart());
140+
LocalDateTime startDateTime = day.At(period.StartTime);
201141
instance = new ShiftInstance((Shift)period, startDateTime, this);
202142
}
203143

@@ -218,7 +158,7 @@ public bool IsDayOff(LocalDate day)
218158

219159
bool dayOff = false;
220160

221-
Rotation shiftRotation = GetRotation();
161+
Rotation shiftRotation = Rotation;
222162
int dayInRotation = GetDayInRotation(day);
223163

224164
// shift or off shift
@@ -258,7 +198,7 @@ public Duration CalculateWorkingTime(LocalDateTime from, LocalDateTime to)
258198
LocalTime thisTime = from.TimeOfDay;
259199
LocalDate toDate = to.Date;
260200
LocalTime toTime = to.TimeOfDay;
261-
int dayCount = GetRotation().GetDayCount();
201+
int dayCount = Rotation.GetDayCount();
262202

263203
// get the working shift from yesterday
264204
Shift lastShift = null;
@@ -326,7 +266,7 @@ public Duration CalculateWorkingTime(LocalDateTime from, LocalDateTime to)
326266
if (rotationEndDate.CompareTo(toDate) < 0)
327267
{
328268
n = dayCount;
329-
sum = sum.Plus(GetRotation().GetWorkingTime());
269+
sum = sum.Plus(Rotation.GetWorkingTime());
330270
}
331271
}
332272

@@ -338,21 +278,6 @@ public Duration CalculateWorkingTime(LocalDateTime from, LocalDateTime to)
338278
return sum;
339279
}
340280

341-
/**
342-
* Get the work schedule that owns this team
343-
*
344-
* @return {@link WorkSchedule}
345-
*/
346-
public WorkSchedule GetWorkSchedule()
347-
{
348-
return workSchedule;
349-
}
350-
351-
internal void SetWorkSchedule(WorkSchedule workSchedule)
352-
{
353-
this.workSchedule = workSchedule;
354-
}
355-
356281
/**
357282
* Compare one team to another
358283
*/
@@ -374,12 +299,11 @@ public override string ToString()
374299
string text = "";
375300
try
376301
{
377-
text = base.ToString() + ", " + rs + ": " + GetRotationStart() + ", " + GetRotation() + ", " + rpct + ": "
302+
text = base.ToString() + ", " + rs + ": " + RotationStart + ", " + Rotation + ", " + rpct + ": "
378303
+ GetPercentageWorked().ToString("0.00") + "%" + ", " + avg + ": " + GetHoursWorkedPerWeek();
379304
}
380305
catch (Exception)
381306
{
382-
// ignore
383307
}
384308

385309
return text;

ShiftSharp/TimePeriod.cs

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,22 @@ public abstract class TimePeriod : Named
3636
private const int SECONDS_PER_DAY = 24 * 60 * 60;
3737

3838
// starting time of day from midnight
39-
private LocalTime startTime;
39+
public LocalTime StartTime { get; set; }
4040

4141
// length of time period
42-
private Duration duration;
42+
public Duration Duration { get; set; }
4343

4444
protected TimePeriod() : base()
4545
{
4646
}
4747

4848
protected TimePeriod(string name, string description, LocalTime startTime, Duration duration) : base(name, description)
4949
{
50-
SetStart(startTime);
51-
SetDuration(duration);
52-
}
53-
54-
/// <summary>
55-
/// Get the period duration
56-
/// </summary>
57-
/// <returns></returns>
58-
public Duration GetDuration()
59-
{
60-
return duration;
61-
}
50+
if (startTime == null)
51+
{
52+
throw new Exception(WorkSchedule.GetMessage("start.not.defined"));
53+
}
6254

63-
/// <summary>
64-
/// Set the duration
65-
/// </summary>
66-
/// <param name="duration">Duration</param>
67-
public void SetDuration(Duration duration)
68-
{
6955
if (duration == null || duration.TotalSeconds == 0)
7056
{
7157
throw new Exception(WorkSchedule.GetMessage("duration.not.defined"));
@@ -75,29 +61,9 @@ public void SetDuration(Duration duration)
7561
{
7662
throw new Exception(WorkSchedule.GetMessage("duration.not.allowed"));
7763
}
78-
this.duration = duration;
79-
}
8064

81-
/// <summary>
82-
/// Get period start time
83-
/// </summary>
84-
/// <returns></returns>
85-
public LocalTime GetStart()
86-
{
87-
return startTime;
88-
}
89-
90-
/// <summary>
91-
/// Set period start time
92-
/// </summary>
93-
/// <param name="startTime">Start time</param>
94-
public void SetStart(LocalTime startTime)
95-
{
96-
if (startTime == null)
97-
{
98-
throw new Exception(WorkSchedule.GetMessage("start.not.defined"));
99-
}
100-
this.startTime = startTime;
65+
this.StartTime = startTime;
66+
this.Duration = duration;
10167
}
10268

10369
/// <summary>
@@ -106,7 +72,7 @@ public void SetStart(LocalTime startTime)
10672
/// <returns>Period end time</returns>
10773
public LocalTime GetEnd()
10874
{
109-
return startTime.PlusSeconds((long)duration.TotalSeconds);
75+
return StartTime.PlusSeconds((long)Duration.TotalSeconds);
11076
}
11177

11278
// breaks are considered to be in the shift's working period
@@ -134,14 +100,12 @@ public override string ToString()
134100

135101
try
136102
{
137-
text = base.ToString() + ", " + start + ": " + GetStart() + " (" + GetDuration() + ")" + ", " + end + ": "
103+
text = base.ToString() + ", " + start + ": " + StartTime + " (" + Duration + ")" + ", " + end + ": "
138104
+ GetEnd();
139105
}
140106
catch (Exception)
141107
{
142-
// ignore
143108
}
144-
145109
return text;
146110
}
147111
}

0 commit comments

Comments
 (0)