public static TimeSpan ToTimeSpan(this TaskTimeSpan timeSpan) { return(timeSpan.Amount * timeSpan.Period switch { TimePeriod.Seconds => TimeSpan.FromSeconds(1), TimePeriod.Minutes => TimeSpan.FromMinutes(1), TimePeriod.Hours => TimeSpan.FromHours(1), TimePeriod.Days => TimeSpan.FromDays(1), TimePeriod.Weeks => TimeSpan.FromDays(7), TimePeriod.Months => TimeSpan.FromDays(DateTimeUtils.DaysInCurrentMonth()), TimePeriod.Years => TimeSpan.FromDays(DateTimeUtils.DaysInCurrentYear()), _ => throw new ArgumentException($"Provided variant of {nameof(TimePeriod)} isn't supported."), });
public void CumulativeTaskTimeSpansLengthTest() { var timeSpansInSeconds = new int[] { 5, 3, 10 }; var task = CreateStudyTaskWithName("taskName"); StudyTaskCollection.Create(base.client).Add(task); DateTime now = DateTime.Now; foreach (var seconds in timeSpansInSeconds) { var taskTimeSpan = new TaskTimeSpan(base.client, task, now); task.TimeSpans.Add(taskTimeSpan); taskTimeSpan.End = now + TimeSpan.FromSeconds(seconds); } var expectedCumulativeLength = TimeSpan.FromSeconds(timeSpansInSeconds.Sum()); Assert.AreEqual(expectedCumulativeLength, task.GetLength()); }
public static TaskTimeSpanService ToService(this TaskTimeSpan timeSpan, IStudyTasksService service) { if (service == null) { throw new ArgumentNullException(nameof(service)); } var task = service.GetTask(timeSpan.TaskId); if (task == null) { throw new ArgumentException($"A task with Id {timeSpan.TaskId} does not exist in the database", nameof(timeSpan)); } return(new TaskTimeSpanService { Id = timeSpan.Id, Start = timeSpan.Start, End = timeSpan.End, TaskId = timeSpan.TaskId }); }