How the Sweden semesterdagar calculator is verified

Inputs

InputFieldType
Earning year (intjänandeår) starts (YYYY-MM-DD)leaveYearStartstring
Earning year (intjänandeår) ends (YYYY-MM-DD)leaveYearEndstring
First day worked in it (YYYY-MM-DD)workStartstring
Last day worked in it (YYYY-MM-DD)workEndstring
Days wholly absent without payunpaidAbsenceDaysnumber
I started after 31 August of the holiday yearstartedAfterAug31boolean
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)
Year Length DaysyearLengthDays$proRataDays(leaveYearStart, leaveYearEnd)
Present DayspresentDays$proRataDays(workStart, workEnd)
Payable DayspayableDays($p := presentDays - $n(unpaidAbsenceDays); $p < 0 ? 0 : $p)
Paid Days RawpaidDaysRawpayableDays / yearLengthDays * $const.statutoryDays
Paid DayspaidDays$clampFloorCap($ceil(paidDaysRaw), 0, $const.statutoryDays)
Leave DaysleaveDays(startedAfterAug31 = true ? $const.lateStartDays : $const.statutoryDays)
Days EntitleddaysEntitled(paidDays < leaveDays ? paidDays : leaveDays)
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
statutoryDays25
lateStartDays5

Test vectors (7)

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 — F1 a full earning year is the familiar 25 days

given leaveYearStart2026-01-01
given leaveYearEnd2026-12-31
given workStart2026-01-01
given workEnd2026-12-31
given unpaidAbsenceDays0
given startedAfterAug31no
given daysTaken0
expect paidDays25
expect daysEntitled25

Case 2 — F2 half a year gives 12.6027, and 7 § rounds it UP to 13 rather than to 13 by luck

given leaveYearStart2026-01-01
given leaveYearEnd2026-12-31
given workStart2026-07-01
given workEnd2026-12-31
given unpaidAbsenceDays0
given startedAfterAug31no
given daysTaken0
expect presentDays184
expect paidDays13
expect daysEntitled13

Case 3 — F3 unpaid absence is subtracted before the division, not after

given leaveYearStart2026-01-01
given leaveYearEnd2026-12-31
given workStart2026-01-01
given workEnd2026-12-31
given unpaidAbsenceDays30
given startedAfterAug31no
given daysTaken0
expect payableDays335
expect paidDays23
expect daysEntitled23

Case 4 — F4 the 31 August cliff: five days, not four months' worth

given leaveYearStart2026-01-01
given leaveYearEnd2026-12-31
given workStart2026-09-01
given workEnd2026-12-31
given unpaidAbsenceDays0
given startedAfterAug31yes
given daysTaken0
expect paidDays9
expect leaveDays5
expect daysEntitled5

Case 5 — F5 a period wider than the earning year is still capped at the statutory 25

given leaveYearStart2026-01-01
given leaveYearEnd2026-12-31
given workStart2020-01-01
given workEnd2030-12-31
given unpaidAbsenceDays0
given startedAfterAug31no
given daysTaken0
expect daysEntitled25

Case 6 — F6 days already taken come off the remainder

given leaveYearStart2026-01-01
given leaveYearEnd2026-12-31
given workStart2026-01-01
given workEnd2026-12-31
given unpaidAbsenceDays0
given startedAfterAug31no
given daysTaken10
expect daysRemaining15

Case 7 — F7 taking more than the entitlement never goes negative

given leaveYearStart2026-01-01
given leaveYearEnd2026-12-31
given workStart2026-01-01
given workEnd2026-12-31
given unpaidAbsenceDays0
given startedAfterAug31no
given daysTaken99
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 Sweden semesterdagar calculator

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