/// <summary> /// Computes time of work for concrete day of some employer. /// </summary> /// <param name="employerID">Unique identifier of employer.</param> /// <param name="day">Date of day of computation.</param> /// <returns>Protocol that collect result of computation and notifications of system.</returns> public ReportProtocol <TimeSpan> TimeOfWorkForDay(int employerID, DateTime day) { ReportProtocol <TimeSpan> protocol = new ReportProtocol <TimeSpan>(); List <EmployerTimeStamp> employerStamps = this.CollectStapmsForDailyReport(employerID, day, protocol.Notifications); // There is errors that can't be repaired. if (protocol.GetNotificationsOfType(NotificationType.Error).Count != 0) { protocol.IsSucceed = false; return(protocol); } if (employerStamps.Count == 0) { protocol.Notifications.Add(new Notification(ReporterMessages.EmployerStampsNotFound, NotificationType.Message)); } TimeSpan result = new TimeSpan(0); for (int i = 0; i < employerStamps.Count - 1; i += 2) { result += employerStamps[i + 1].Time - employerStamps[i].Time; } protocol.Result = result; protocol.IsSucceed = true; return(protocol); }
/// <summary> /// Find all respites of employer for day. /// </summary> /// <param name="employerID">Unique identifier of employer.</param> /// <param name="day">Target day.</param> /// <param name="maxDuration">Maximum duration of respite.</param> /// <returns>Collection of all respites.</returns> public ReportProtocol <List <Respite> > RespitesForDay(int employerID, DateTime day, TimeSpan maxDuration) { ReportProtocol <List <Respite> > protocol = new ReportProtocol <List <Respite> >(); List <EmployerTimeStamp> employerStamps = this.CollectStapmsForDailyReport(employerID, day, protocol.Notifications); // There is errors that can't be repaired. if (protocol.GetNotificationsOfType(NotificationType.Error).Count != 0) { protocol.IsSucceed = false; return(protocol); } if (employerStamps.Count == 0) { protocol.Notifications.Add(new Notification(ReporterMessages.EmployerStampsNotFound, NotificationType.Message)); } List <Respite> result = new List <Respite>(); // Start with i equals 1 because we interested of when // employer Out and when In but first stamp is In. for (int i = 1; i < employerStamps.Count - 1; i += 2) { var duration = employerStamps[i + 1].Time - employerStamps[i].Time; if (duration <= maxDuration) { result.Add(new Respite(employerStamps[i].Time, employerStamps[i + 1].Time)); } } protocol.Result = result; protocol.IsSucceed = true; return(protocol); }