How the Saudi Arabia annual leave calculator is verified

Inputs

InputFieldType
Consecutive years with this employerserviceYearsnumber
Months worked in this leave yearmonthsWorkednumber
Days already takendaysTakennumber

The formula

Each derived value below is computed by the Valem engine from the expression shown, in this order. Nothing else runs — there is no hidden code path.

Derived valueFieldFormula (JSONata)
Completed YearscompletedYears$floor($n(serviceYears))
Annual EntitlementannualEntitlementcompletedYears >= $const.longServiceYears ? $const.daysAfterLongService : $const.daysBase
Days EntitleddaysEntitled($m := $n(monthsWorked); $m := $m > 12 ? 12 : ($m < 0 ? 0 : $m); $round(annualEntitlement * $m / 12, 1))
Days RemainingdaysRemaining($r := daysEntitled - $n(daysTaken); $r < 0 ? 0 : $round($r, 1))

Rates and thresholds

The expressions above read these as $const. They are the figures the annual refresh replaces, so they live as data rather than being written into the formulas — which is what makes a year-on-year change a one-line diff instead of an edit to arithmetic.

ConstantValue
daysBase21
daysAfterLongService30
longServiceYears5

Test vectors (8)

Every case is executed against this model on each build, by the Java engine and independently by a JavaScript one. A mismatch of a single cent fails the build, so the page cannot ship advertising a figure the model no longer produces.

Case 1 — S1 a full year in the first five gives 21

given serviceYears2
given monthsWorked12
given daysTaken0
expect daysEntitled21

Case 2 — S2 four completed years is still 21

given serviceYears4.9
given monthsWorked12
given daysTaken0
expect completedYears4
expect daysEntitled21

Case 3 — S3 five consecutive years lifts the minimum to 30

given serviceYears5
given monthsWorked12
given daysTaken0
expect annualEntitlement30
expect daysEntitled30

Case 4 — S4 and it stays at 30

given serviceYears25
given monthsWorked12
given daysTaken0
expect daysEntitled30

Case 5 — S5 half a year at 21 is 10.5 (art. 111 proportion)

given serviceYears1
given monthsWorked6
given daysTaken0
expect daysEntitled10.5

Case 6 — S6 four months at 30 is 10

given serviceYears6
given monthsWorked4
given daysTaken0
expect daysEntitled10

Case 7 — S7 days taken come off the remainder

given serviceYears5
given monthsWorked12
given daysTaken12
expect daysRemaining18

Case 8 — S8 taking more than the entitlement never goes negative

given serviceYears1
given monthsWorked12
given daysTaken40
expect daysRemaining0

Sources

Check it yourself — and reuse it

The whole model as JSON — inputs, outputs, formulas, vectors and sources in one re-runnable document.

This model is published under CC BY 4.0: use it, adapt it, build on it, with attribution. The licence covers the model — the expression of each rule and the arrangement of the catalog. The rates and thresholds are law, and nobody licenses those; the sources above are where they come from.

← Back to the Saudi Arabia annual leave calculator

Built with Valem — a live, verifiable calculator you can fork and embed.