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:
IT狗
2026-07-21 17:41:14 +08:00
parent 6f2df815f5
commit f41dad6127
+8 -4
View File
@@ -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) expected_end_dt = datetime.combine(check_out_dt.date(), shift_end)
if check_out_dt < expected_end_dt: if check_out_dt < expected_end_dt:
diff = (expected_end_dt - check_out_dt).total_seconds() / 60 diff_seconds = (expected_end_dt - check_out_dt).total_seconds()
result["early_minutes"] = round(diff) result["early_minutes"] = round(diff_seconds / 60) if diff_seconds >= 30 else 0
# Calculate OT minutes (leaving after scheduled end) # Calculate OT minutes (leaving after scheduled end)
if check_out_dt > expected_end_dt: if check_out_dt > expected_end_dt:
diff = (check_out_dt - expected_end_dt).total_seconds() / 60 diff_seconds = (check_out_dt - expected_end_dt).total_seconds()
result["ot_minutes"] = round(diff) # 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 # Determine status code and text
status_parts = [] status_parts = []