How the Hong Kong paid annual leave calculator is verified

Inputs

InputFieldType
Years of service under a continuous contractserviceYearsnumber
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))
Days EntitleddaysEntitled($y := completedYears; $y < $const.qualifyingYears ? 0 : ($y <= $const.bandYear2 ? $const.daysYears1to2 : ($y = $const.bandYear3 ? $const.daysYear3 : ($y = $const.bandYear4 ? $const.daysYear4 : ($y = $const.bandYear5 ? $const.daysYear5 : ($y = $const.bandYear6 ? $const.daysYear6 : ($y = $const.bandYear7 ? $const.daysYear7 : ($y = $const.bandYear8 ? $const.daysYear8 : $const.daysYear9Plus))))))))
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
daysYears1to27
daysYear38
daysYear49
daysYear510
daysYear611
daysYear712
daysYear813
daysYear9Plus14
bandYear22
bandYear33
bandYear44
bandYear55
bandYear66
bandYear77
bandYear88
bandYear99
qualifyingYears1

Test vectors (11)

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 — N1 under a year there is no entitlement yet

given serviceYears0
given daysTaken0
expect daysEntitled0

Case 2 — N2 the first year gives 7

given serviceYears1
given daysTaken0
expect daysEntitled7

Case 3 — N3 the SECOND year also gives 7 — the table does not step yet

given serviceYears2
given daysTaken0
expect daysEntitled7

Case 4 — N4 the third year is the first increase, to 8

given serviceYears3
given daysTaken0
expect daysEntitled8

Case 5 — N5 the fifth year is 10

given serviceYears5
given daysTaken0
expect daysEntitled10

Case 6 — N6 the eighth year is 13

given serviceYears8
given daysTaken0
expect daysEntitled13

Case 7 — N7 nine years reaches the maximum of 14

given serviceYears9
given daysTaken0
expect daysEntitled14

Case 8 — N8 and it stays at 14 thereafter

given serviceYears30
given daysTaken0
expect daysEntitled14

Case 9 — N9 a part year does not move the band

given serviceYears4.9
given daysTaken0
expect completedYears4
expect daysEntitled9

Case 10 — N10 days already taken come off the remainder

given serviceYears9
given daysTaken5
expect daysRemaining9

Case 11 — N11 taking more than the entitlement never goes negative

given serviceYears1
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 Hong Kong paid annual leave calculator

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