internal void HandleShift(int hour, int minute, WorkTime required) { if (CurrentShiftStart.NotFilled()) { CurrentShiftStart.Hour = hour; CurrentShiftStart.Minute = minute; } else { // close shift TimeSpan currentShiftEndAt = new TimeSpan(hour, minute, 0); // 17:23 TimeSpan currentShiftStartAt = new TimeSpan(CurrentShiftStart.Hour, CurrentShiftStart.Minute, 0); // 08:24 TimeSpan requiredSpan = new TimeSpan(required.Hour, required.Minute, 0); TimeSpan currentShiftBalance = currentShiftEndAt - currentShiftStartAt; TimeSpan currentDayTotalBalance = currentShiftBalance - requiredSpan; TimeSpan currentMonthTotalTotalSpan = new TimeSpan(CurrentMonthTotal.Hour, CurrentMonthTotal.Minute, 0); currentMonthTotalTotalSpan += currentDayTotalBalance; CurrentMonthTotal = new WorkTime { Hour = currentMonthTotalTotalSpan.Hours, Minute = currentMonthTotalTotalSpan.Minutes }; CurrentShiftStart = new WorkTime(); } }
internal string CurrentShiftTimeLeft(WorkTime required) { if (CurrentShiftStart.NotFilled()) { CurrentShiftStart = new WorkTime(); return(CurrentShiftStart.ToTimeDisplay()); } TimeSpan requiredSpan = new TimeSpan(required.Hour, required.Minute, 0); TimeSpan predEnd = new TimeSpan(CurrentShiftStart.Hour, CurrentShiftStart.Minute, 0) + requiredSpan; TimeSpan actualBalance = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, 0) - new TimeSpan(CurrentShiftStart.Hour, CurrentShiftStart.Minute, 0) - requiredSpan; string balanceStr = actualBalance.ToTimeDisplay(); if (actualBalance > new TimeSpan(0, 0, 0)) // extra hours { balanceStr += " EX"; } return(balanceStr + " | " + new WorkTime { Hour = predEnd.Hours, Minute = predEnd.Minutes }.ToTimeDisplay()); }