public HourProcessor(DateTime ti, DateTime to, DateTime startduty, DateTime endduty) { /* HOUR PROCESSOR V2.0 * DateTime start = new DateTime (4,1,1,2,30,00); * DateTime end = new DateTime (4,1,1,22,30,00); * int sm = start.Hour * 60 + start.Minute; * int em = end.Hour * 60 + end.Minute; * int duration = em - sm; * if (duration<0) * duration+=1440; * TimeSpan ti = new TimeSpan(0,duration, 0); */ DateTime NightStart = new DateTime(ti.Year, ti.Month, ti.Day, 22, 00, 00); DateTime NightEnd = new DateTime(ti.Year, ti.Month, ti.Day, 6, 00, 00); DateTime Midnight = new DateTime(ti.Year, ti.Month, ti.Day, 0, 0, 0).AddDays(1); DateTime maxStart; DateTime minEnd; DateTime minStart; DateTime maxEnd; // if not same if (ti > to) { to = to.AddDays(1); endduty = endduty.AddDays(1); NightEnd = NightEnd.AddDays(1); // First Half // 1: Max Selection, either nighstart or actuals maxStart = ti < NightStart ? NightStart : ti; minStart = ti < NightStart ? ti : NightStart; TimeSpan d1_night = Midnight - maxStart; TimeSpan d1_day = (NightStart - minStart > TimeSpan.FromSeconds(0)) ? NightStart - minStart : new TimeSpan(0, 0, 0); // Second Half minEnd = to < NightEnd ? to : NightEnd; maxEnd = to > NightEnd ? to : NightEnd; TimeSpan d2_night = minEnd - Midnight; TimeSpan d2_day = (maxEnd - NightEnd > TimeSpan.FromSeconds(0)) ? maxEnd - NightEnd : new TimeSpan(0, 0, 0); TimeSpan d2_overtime_day = new TimeSpan(0, 0, 0); TimeSpan d2_overtime_night = new TimeSpan(0, 0, 0); // Check for overtimes if (to > endduty) { DateTime minEndOver_night = to < NightEnd ? to : NightEnd; DateTime maxEndOver_day = to > NightEnd ? to : NightEnd; d2_overtime_night = (endduty - minEndOver_night > TimeSpan.FromSeconds(0)) ? endduty - minEndOver_night : new TimeSpan(0, 0, 0); d2_overtime_day = (maxEndOver_day - endduty > TimeSpan.FromSeconds(0)) ? maxEndOver_day - endduty : new TimeSpan(0, 0, 0); d2_day -= d2_overtime_day; d2_night -= d2_overtime_night; } Attendance.HE_internal o = Attendance.IsHolidayToday_(ti); // Check if today is holiday. if (o.isholiday) { if (o.type == Enumeration.HolidayType.Regular) { if (ti.DayOfWeek == DayOfWeek.Sunday) { this.hp["sun_proper_day_regular"] += d1_day; this.hp["sun_proper_night_regular"] += d1_night; } else { this.hp["nsu_proper_day_regular"] += d1_day; this.hp["nsu_proper_night_regular"] += d1_night; } } else { if (ti.DayOfWeek == DayOfWeek.Sunday) { this.hp["sun_proper_day_special"] += d1_day; this.hp["sun_proper_night_special"] += d1_night; } else { this.hp["nsu_proper_day_special"] += d1_day; this.hp["nsu_proper_night_special"] += d1_night; } } } else { if (ti.DayOfWeek == DayOfWeek.Sunday) { this.hp["sun_proper_day_normal"] += d1_day; this.hp["sun_proper_night_normal"] += d1_night; } else { this.hp["nsu_proper_day_normal"] += d1_day; this.hp["nsu_proper_night_normal"] += d1_night; } } //Check if tomorrow is holiday. o = Attendance.IsHolidayToday_(ti.AddDays(1)); if (o.isholiday) { if (o.type == Enumeration.HolidayType.Regular) { if (ti.DayOfWeek == DayOfWeek.Sunday) { this.hp["sun_proper_day_regular"] += d2_day; this.hp["sun_proper_night_regular"] += d2_night; this.hp["sun_overtime_day_regular"] += d2_overtime_day; this.hp["sun_overtime_night_regular"] += d2_overtime_night; } else { this.hp["nsu_proper_day_regular"] += d2_day; this.hp["nsu_proper_night_regular"] += d2_night; this.hp["nsu_overtime_day_regular"] += d2_overtime_day; this.hp["nsu_overtime_night_regular"] += d2_overtime_night; } } else { if (ti.DayOfWeek == DayOfWeek.Sunday) { this.hp["sun_proper_day_special"] += d2_day; this.hp["sun_proper_night_special"] += d2_night; this.hp["sun_overtime_day_special"] += d2_overtime_day; this.hp["sun_overtime_night_special"] += d2_overtime_night; } else { this.hp["nsu_proper_day_special"] += d2_day; this.hp["nsu_proper_night_special"] += d2_night; this.hp["nsu_overtime_day_special"] += d2_overtime_day; this.hp["nsu_overtime_night_special"] += d2_overtime_night; } } } else { if (ti.DayOfWeek == DayOfWeek.Sunday) { this.hp["sun_proper_day_normal"] += d2_day; this.hp["sun_proper_night_normal"] += d2_night; this.hp["sun_overtime_day_normal"] += d2_overtime_day; this.hp["sun_overtime_night_normal"] += d2_overtime_night; } else { this.hp["nsu_proper_day_normal"] += d2_day; this.hp["nsu_proper_night_normal"] += d2_night; this.hp["nsu_overtime_day_normal"] += d2_overtime_day; this.hp["nsu_overtime_night_normal"] += d2_overtime_night; } } } else { // if same day NightEnd = new DateTime(ti.Year, ti.Month, ti.Day, 6, 00, 00); Midnight = new DateTime(ti.Year, ti.Month, ti.Day, 0, 0, 0); DateTime MidnightNext = Midnight.AddDays(1); TimeSpan day = new TimeSpan(0, 0, 0); TimeSpan night = new TimeSpan(0, 0, 0); night += GetOverlap(Midnight, NightEnd, ti, to); night += GetOverlap(NightStart, MidnightNext, ti, to); day += GetOverlap(NightEnd, NightStart, ti, to); // Overtime Component TimeSpan overtimeday, overtimenight; overtimeday = overtimenight = new TimeSpan(0, 0, 0); if (to > endduty) { DateTime minEndOver_day = to < NightStart ? to : NightStart; overtimeday = (minEndOver_day - endduty > TimeSpan.FromSeconds(0)) ? minEndOver_day - endduty : new TimeSpan(0, 0, 0); overtimenight = to > NightStart ? to - NightStart : new TimeSpan(0, 0, 0); day -= overtimeday; night -= overtimenight; } Attendance.HE_internal o = Attendance.IsHolidayToday_(ti); // Check if today is holiday. if (o.isholiday) { if (o.type == Enumeration.HolidayType.Regular) { if (ti.DayOfWeek == DayOfWeek.Sunday) { this.hp["sun_proper_day_regular"] += day; this.hp["sun_proper_night_regular"] += night; this.hp["sun_overtime_day_regular"] += overtimeday; this.hp["sun_overtime_night_regular"] += overtimenight; } else { this.hp["nsu_proper_day_regular"] += day; this.hp["nsu_proper_night_regular"] += night; this.hp["nsu_overtime_day_regular"] += overtimeday; this.hp["nsu_overtime_night_regular"] += overtimenight; } } else { if (ti.DayOfWeek == DayOfWeek.Sunday) { this.hp["sun_proper_day_special"] += day; this.hp["sun_proper_night_special"] += night; this.hp["sun_overtime_day_special"] += overtimeday; this.hp["sun_overtime_night_special"] += overtimenight; } else { this.hp["nsu_proper_day_special"] += day; this.hp["nsu_proper_night_special"] += night; this.hp["nsu_overtime_day_special"] += overtimeday; this.hp["nsu_overtime_night_special"] += overtimenight; } } } else { if (ti.DayOfWeek == DayOfWeek.Sunday) { this.hp["sun_proper_day_normal"] += day; this.hp["sun_proper_night_normal"] += night; this.hp["sun_overtime_day_normal"] += overtimeday; this.hp["sun_overtime_night_normal"] += overtimenight; } else { this.hp["nsu_proper_day_normal"] += day; this.hp["nsu_proper_night_normal"] += night; this.hp["nsu_overtime_day_normal"] += overtimeday; this.hp["nsu_overtime_night_normal"] += overtimenight; } } } }
public Hours(DateTime TimeIn, DateTime TimeOut, DateTime f) { DateTime NightStart = new DateTime(f.Year, f.Month, f.Day, 22, 00, 00); DateTime NightEnd = new DateTime(f.Year, f.Month, f.Day, 6, 00, 00); DateTime Midnight = new DateTime(f.Year, f.Month, f.Day, 0, 0, 0).AddDays(1); DateTime maxStart; DateTime minEnd; DateTime minStart; DateTime maxEnd; // if not same if (TimeIn > TimeOut) { TimeOut = TimeOut.AddDays(1); NightEnd = NightEnd.AddDays(1); // First Half // 1: Max Selection, either nighstart or actuals maxStart = TimeIn < NightStart ? NightStart : TimeIn; minStart = TimeIn < NightStart ? TimeIn : NightStart; TimeSpan d1_night = Midnight - maxStart; TimeSpan d1_day = (NightStart - minStart > TimeSpan.FromSeconds(0)) ? NightStart - minStart : new TimeSpan(0, 0, 0); if (TimeIn.DayOfWeek == DayOfWeek.Sunday) { SundayTotal += d1_day + d1_night; } // Second Half minEnd = TimeOut < NightEnd ? TimeOut : NightEnd; maxEnd = TimeOut > NightEnd ? TimeOut : NightEnd; TimeSpan d2_night = minEnd - Midnight; TimeSpan d2_day = (maxEnd - NightEnd > TimeSpan.FromSeconds(0)) ? maxEnd - NightEnd : new TimeSpan(0, 0, 0); if (TimeOut.DayOfWeek == DayOfWeek.Sunday) { SundayTotal += d2_day + d2_night; } Attendance.HE_internal o = Attendance.IsHolidayToday_(TimeIn); // Check if today is holiday. if (Attendance.IsHolidayToday(TimeIn)) { holiday_night += d1_night; holiday_day += d1_day; if (o.type == Enumeration.HolidayType.Regular) { if (TimeIn.DayOfWeek == DayOfWeek.Sunday) { holiday_regular_day_sunday += d1_day; holiday_sunday_regular_night += d1_night; } else { } } else { Sunday_special_day += d1_day; Sunday_special_night += d1_night; } } else { normal_night += d1_night; normal_day += d1_day; if (TimeIn.DayOfWeek == DayOfWeek.Sunday) { Sunday_normal_day += d1_day; Sunday_normal_night += d1_night; } } //Check if tomorrow is holiday. if (Attendance.IsHolidayTomorrow(TimeIn)) { holiday_night += d2_night; holiday_day += d2_day; if (TimeOut.DayOfWeek == DayOfWeek.Sunday) { // Sunday_holiday_day += d2_day; // Sunday_holiday_night += d2_night; } } else { normal_night += d2_night; normal_day += d2_day; if (TimeOut.DayOfWeek == DayOfWeek.Sunday) { Sunday_normal_day += d2_day; Sunday_normal_night += d2_night; } } } else { // if same day NightEnd = new DateTime(f.Year, f.Month, f.Day, 6, 00, 00); maxStart = TimeIn < NightStart ? TimeIn : NightStart; minStart = TimeIn > NightStart ? TimeIn : NightStart; minEnd = TimeOut < NightEnd ? TimeOut : NightEnd; maxEnd = TimeOut > NightEnd ? TimeOut : NightEnd; if (Attendance.IsHolidayToday(TimeIn)) { holiday_night += (minEnd - maxStart) > TimeSpan.FromSeconds(0) ? minEnd - maxStart : new TimeSpan(0, 0, 0); holiday_day += (TimeOut - NightEnd) > TimeSpan.FromSeconds(0) ? TimeOut - NightEnd : new TimeSpan(0, 0, 0); holiday_day += (NightStart - minStart) > TimeSpan.FromSeconds(0) ? NightStart - minStart : new TimeSpan(0, 0, 0); if (TimeIn.DayOfWeek == DayOfWeek.Sunday) { SundayTotal += holiday_night + holiday_day; // Sunday_holiday_day += holiday_day; // Sunday_holiday_night += holiday_night; } } else { normal_night += (minEnd - maxStart) > TimeSpan.FromSeconds(0) ? minEnd - maxStart : new TimeSpan(0, 0, 0); normal_day += (TimeOut - NightEnd) > TimeSpan.FromSeconds(0) ? TimeOut - NightEnd : new TimeSpan(0, 0, 0); normal_day += (NightStart - minStart) > TimeSpan.FromSeconds(0) ? NightStart - minStart : new TimeSpan(0, 0, 0); if (TimeIn.DayOfWeek == DayOfWeek.Sunday) { SundayTotal += normal_night + normal_day; Sunday_normal_day += normal_day; Sunday_normal_night += normal_night; } } } total = normal_day + normal_night + holiday_day + holiday_night; }