public AttendanceStatus CalculateStatus(AttendanceLog lastLog) { if (lastLog == null) { return(AttendanceStatus.CheckIn); } var diff = LogDate.Subtract(lastLog.LogDate); var totalHours = Math.Round(diff.TotalHours, 2); if (totalHours - GlobalConfig.MaxWorkingHours >= 0.00) { // if new log date is more than 16 hours after last log date. // system think it is one check in. return(AttendanceStatus.CheckIn); } if (GlobalConfig.MaxWorkingHours - totalHours > 0.00 && totalHours - GlobalConfig.MinWorkingHours >= 0.00) { if (lastLog.LogStatus == AttendanceStatus.CheckIn) { return(AttendanceStatus.CheckOut); } if (lastLog.LogStatus == AttendanceStatus.CheckOut) { return(AttendanceStatus.CheckIn); } } if (GlobalConfig.MinWorkingHours - totalHours > 0.00) { // time range is less than 30 minutes, system think it is a duplicated attendance log. if (lastLog.LogStatus == AttendanceStatus.CheckIn) { return(AttendanceStatus.CheckIn); } if (lastLog.LogStatus == AttendanceStatus.CheckOut) { return(AttendanceStatus.CheckOut); } } throw new NotSupportedException("Unknown attendance status."); }
public AttendanceStatus CalculateStatus(AttendanceLog lastLog) { if (lastLog == null) { return(AttendanceStatus.CheckIn); } var diff = LogDate.Subtract(lastLog.LogDate); if (diff.TotalHours >= 16) { // if new log date is more than 16 hours after last log date. // system think it is one check in. return(AttendanceStatus.CheckIn); } if (diff.TotalHours < 16 && diff.TotalHours > 0.5) { if (lastLog.LogStatus == AttendanceStatus.CheckIn) { return(AttendanceStatus.CheckOut); } if (lastLog.LogStatus == AttendanceStatus.CheckOut) { return(AttendanceStatus.CheckIn); } } if (diff.TotalHours < 0.5) { // time range is less than 30 minutes, system think it is a duplicated attendance log. if (lastLog.LogStatus == AttendanceStatus.CheckIn) { return(AttendanceStatus.CheckIn); } if (lastLog.LogStatus == AttendanceStatus.CheckOut) { return(AttendanceStatus.CheckOut); } } throw new NotSupportedException("Unknown attendance status."); }