|
| 1 | +/* |
| 2 | +MIT License |
| 3 | +
|
| 4 | +Copyright (c) 2016 Kent Randall |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +of this software and associated documentation files (the "Software"), to deal |
| 8 | +in the Software without restriction, including without limitation the rights |
| 9 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +copies of the Software, and to permit persons to whom the Software is |
| 11 | +furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in all |
| 14 | +copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +SOFTWARE. |
| 23 | +*/ |
| 24 | + |
| 25 | +using NodaTime; |
| 26 | +using System; |
| 27 | + |
| 28 | +namespace Point85.ShiftSharp.Schedule |
| 29 | +{ |
| 30 | + /// <summary> |
| 31 | + /// Class ShiftInstance is an instance of a {@link Shift}. A shift instance is worked by a Team. |
| 32 | + /// </summary> |
| 33 | + public class ShiftInstance : IComparable<ShiftInstance> |
| 34 | + { |
| 35 | + // definition of the shift |
| 36 | + private Shift shift; |
| 37 | + |
| 38 | + // team working it |
| 39 | + private Team team; |
| 40 | + |
| 41 | + // start date and time of day |
| 42 | + private LocalDateTime startDateTime; |
| 43 | + |
| 44 | + internal ShiftInstance(Shift shift, LocalDateTime startDateTime, Team team) |
| 45 | + { |
| 46 | + this.shift = shift; |
| 47 | + this.startDateTime = startDateTime; |
| 48 | + this.team = team; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Get the shift for this instance |
| 53 | + * |
| 54 | + * @return {@link Shift} |
| 55 | + */ |
| 56 | + public Shift GetShift() |
| 57 | + { |
| 58 | + return shift; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Get the starting date and time of day |
| 63 | + * |
| 64 | + * @return LocalDateTime |
| 65 | + */ |
| 66 | + public LocalDateTime GetStartTime() |
| 67 | + { |
| 68 | + return startDateTime; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Get the end date and time of day |
| 73 | + * |
| 74 | + * @return LocalDateTime |
| 75 | + */ |
| 76 | + public LocalDateTime GetEndTime() |
| 77 | + { |
| 78 | + Duration duration = shift.GetDuration(); |
| 79 | + return startDateTime.PlusSeconds((long)duration.TotalSeconds); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Get the team |
| 84 | + * |
| 85 | + * @return {@link Team} |
| 86 | + */ |
| 87 | + public Team GetTeam() |
| 88 | + { |
| 89 | + return team; |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Compare this non-working period to another such period by start time of |
| 94 | + * day |
| 95 | + * |
| 96 | + * @return -1 if less than, 0 if equal and 1 if greater than |
| 97 | + */ |
| 98 | + public int CompareTo(ShiftInstance other) |
| 99 | + { |
| 100 | + throw new NotImplementedException(); |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Build a string representation of a shift instance |
| 105 | + */ |
| 106 | + public override string ToString() |
| 107 | + { |
| 108 | + string t = WorkSchedule.GetMessage("team"); |
| 109 | + string s = WorkSchedule.GetMessage("shift"); |
| 110 | + string ps = WorkSchedule.GetMessage("period.start"); |
| 111 | + string pe = WorkSchedule.GetMessage("period.end"); |
| 112 | + |
| 113 | + string text = " " + t + ": " + GetTeam().GetName() + ", " + s + ": " + GetShift().GetName() + ", " + ps + ": " |
| 114 | + + GetStartTime() + ", " + pe + ": " + GetEndTime(); |
| 115 | + return text; |
| 116 | + } |
| 117 | + |
| 118 | + } |
| 119 | +} |
0 commit comments