Debug School

ashley
ashley

Posted on

Modeling PTO Accrual in Code: Pay Period Drift, 27-Paycheck Years, and Cap Bounds

Modeling PTO Accrual in Code: Pay Period Drift, 27-Paycheck Years, and Cap Bounds

Paid Time Off (PTO) calculation seems like simple addition: accrued = hours_per_period * periods. But when you implement accrual rules in a HRIS or payroll system, edge cases like leap years, bi-weekly pay period drift (27 paychecks in a calendar year), mid-period hire dates, and accrual caps lead to subtle balance discrepancies.

The accrual frequency problem

PTO is typically awarded on one of three schedules:

  • Per pay period: Added every time payroll runs (e.g., 80-hour biweekly or semi-monthly).
  • Monthly: Added on the 1st or last day of the calendar month.
  • Lump sum / Annual: Granted at the start of the year or anniversary date.

The 27-paycheck anomaly

Biweekly pay periods happen every 14 days ($364$ days per 26 pay periods). Because a calendar year has 365 (or 366) days, every 11 to 12 years a calendar year contains 27 pay dates instead of 26.

If your accrual engine adds annual_pto / 26 per paycheck without checking the calendar year's pay date count, employees in a 27-paycheck year will accrue $103.8\%$ of their annual target allotment.

Three accrual cap models

Employers enforce caps to limit balance liability. In code, caps must be evaluated in the exact sequence specified by policy:

1. Max Balance Cap (Hard Stop)

The balance cannot exceed a maximum value $M$.
$$\text{New Balance} = \min(\text{Current Balance} + \text{Accrued}, M)$$
Edge case: If an employee is at the cap, takes 8 hours of leave on Tuesday, and payroll runs on Friday, does the leave deduction happen before or after the accrual check? Deducting leave first allows the employee to earn back accrued hours up to the cap.

2. Annual Carryover Cap (Year-End Reset)

Employees can carry over up to $C$ hours into the new year. Any excess is forfeited on December 31 (or anniversary date).
$$\text{Balance}{\text{Jan 1}} = \min(\text{Balance}{\text{Dec 31}}, C)$$

3. Use-It-or-Lose-It (Zero Carryover)

All unused balance resets to 0 at year-end.

Mid-period pro-rating

When an employee starts or terminates mid-pay-period, accrual should be pro-rated based on active calendar days or worked hours:

$$\text{Prorated Accrual} = \text{Full Period Accrual} \times \frac{\text{Active Days in Period}}{\text{Total Days in Period}}$$

Using floating-point division without rounding rules (e.g., rounding to 4 decimal places internally and 2 decimal places for display) will create a 0.0001 hour discrepancy over a full year.

Implementation recommendations

  1. Calculate on fixed UTC dates: Store accrual transaction timestamps in UTC to avoid daylight saving time double-counting or skipping 1-hour shifts.
  2. Atomic transactions: Record accruals and deductions as immutable ledger entries (+3.33 hrs accrual, -8.00 hrs usage) rather than mutating a single balance field.
  3. Explicit cap evaluation order: Always run Deductions \to Accrual \to Cap Check in strict order during payroll runs.

Testing PTO balance models

When validating PTO accrual logic or calculating projected vacation balances for budgeting, using a dedicated calculator helps test rollover caps and period accrual schedules. The PTO calculator at Miryori models accrual rates, carryover limits, and projected balances client-side in your browser.

Note: code examples illustrate HR tech calculations and are not employment law guidance.

Top comments (0)