|
| 1 | +namespace DotNet.DocsTools.Utility; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// Manage start and end dates for a single sprint. |
| 5 | +/// </summary> |
| 6 | +/// <remarks> |
| 7 | +/// Static methods find a sprint based on a date, and an offset from that date. |
| 8 | +/// Instance members retrieve the start date, end date, and title for the sprint. |
| 9 | +/// </remarks> |
| 10 | +public class SprintDateRange |
| 11 | +{ |
| 12 | + /// <summary> |
| 13 | + /// Retrieve the sprint object for a given date. |
| 14 | + /// </summary> |
| 15 | + /// <param name="selectedDate">The date selected</param> |
| 16 | + /// <returns>A SprintDateRange object for the current sprint.</returns> |
| 17 | + /// <exception cref="ArgumentOutOfRangeException"> |
| 18 | + /// When the date is outside of the range of the known sprints. |
| 19 | + /// </exception> |
| 20 | + public static SprintDateRange GetSprintFor(DateTime selectedDate) |
| 21 | + { |
| 22 | + var sprintName = selectedDate.ToString("MMMM yyyy"); |
| 23 | + var sprintStartDate = new DateTime(selectedDate.Year, selectedDate.Month, 1); |
| 24 | + var sprintEndDate = sprintStartDate.AddMonths(1).AddDays(-1); |
| 25 | + return new SprintDateRange(sprintName, sprintStartDate, sprintEndDate); |
| 26 | + } |
| 27 | + |
| 28 | + /// <summary> |
| 29 | + /// Retrieve a sprint based on a date and an offset. |
| 30 | + /// </summary> |
| 31 | + /// <param name="offset">The offset (positive or negative) from the selected date.</param> |
| 32 | + /// <param name="selectedDate">The chosen date to start from.</param> |
| 33 | + /// <returns>A SprintDateRange object that represents the selected sprint.</returns> |
| 34 | + /// <exception cref="ArgumentOutOfRangeException"> |
| 35 | + /// When the date and offset produce a sprint outside of the known range. |
| 36 | + /// </exception> |
| 37 | + public static SprintDateRange GetOffsetSprintFor(int offset, DateTime selectedDate) |
| 38 | + { |
| 39 | + var startDate = selectedDate.AddMonths(offset); |
| 40 | + return GetSprintFor(startDate); |
| 41 | + } |
| 42 | + |
| 43 | + private SprintDateRange(string sprintName, DateTime startDate, DateTime endDate) |
| 44 | + { |
| 45 | + SprintName = sprintName; |
| 46 | + StartDate = startDate; |
| 47 | + EndDate = endDate; |
| 48 | + } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Retrieve the name of the sprint |
| 52 | + /// </summary> |
| 53 | + /// <returns></returns> |
| 54 | + public override string ToString() => SprintName; |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// The first date of the sprint. |
| 58 | + /// </summary> |
| 59 | + public DateTime StartDate { get; } |
| 60 | + |
| 61 | + /// <summary> |
| 62 | + /// The last date of the sprint. |
| 63 | + /// </summary> |
| 64 | + public DateTime EndDate { get; } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// The name of the sprint, as used in all reporting. |
| 68 | + /// </summary> |
| 69 | + public string SprintName { get; } |
| 70 | +} |
0 commit comments