Fix: add 30-second tolerance for OT/early/late calculation to avoid floating-point noise (e.g. 20:00==20:00 showing OT 1min)
This commit is contained in:
+8
-4
@@ -705,13 +705,17 @@ def calculate_attendance_status(check_in, check_out, shift_start, shift_end):
|
||||
expected_end_dt = datetime.combine(check_out_dt.date(), shift_end)
|
||||
|
||||
if check_out_dt < expected_end_dt:
|
||||
diff = (expected_end_dt - check_out_dt).total_seconds() / 60
|
||||
result["early_minutes"] = round(diff)
|
||||
diff_seconds = (expected_end_dt - check_out_dt).total_seconds()
|
||||
result["early_minutes"] = round(diff_seconds / 60) if diff_seconds >= 30 else 0
|
||||
|
||||
# Calculate OT minutes (leaving after scheduled end)
|
||||
if check_out_dt > expected_end_dt:
|
||||
diff = (check_out_dt - expected_end_dt).total_seconds() / 60
|
||||
result["ot_minutes"] = round(diff)
|
||||
diff_seconds = (check_out_dt - expected_end_dt).total_seconds()
|
||||
# Ignore tiny differences (< 30 seconds) to avoid floating-point noise
|
||||
if diff_seconds >= 30:
|
||||
result["ot_minutes"] = round(diff_seconds / 60)
|
||||
else:
|
||||
result["ot_minutes"] = 0
|
||||
|
||||
# Determine status code and text
|
||||
status_parts = []
|
||||
|
||||
Reference in New Issue
Block a user