Skip to content

Leave approved before a holiday was announced stays charged

The rule

Some employers, or agreements, treat a holiday announced late (a day declared a public holiday at short notice) differently for the leave that was already approved: the day was booked and approved as leave, and stays leave, charged to the balance; only leave approved once the holiday was known draws nothing. Everywhere that does not say so, the usual practice (the recipe leave_on_holidays) is that a holiday draws nothing from the balance whenever it was announced.

Who uses it

Employers with a contract or a policy that says leave approved before the announcement stays charged. It is the employer’s own rule: Time and Attendance does not decide it, it gives the facts the rule reads.

How the recipe does it

Two facts, and a short rule of the business’s own in the package’s main.lua (leave_charged_before_announcement, a leave step):

  • ctx:day(date).holidays[i].announced: when the date of the holiday was first given (an instant in milliseconds: when the setup revision that first gave the date was stored). It is not there where it is not known.
  • ctx.request.approved: when the request was approved (the decision that approved it, as it was stored), and ctx.request.recorded, when it was asked for. approved is not there while the request is not approved.

The step books no time (ctx:book(date, 0)) on a holiday’s day unless the request was approved before the holiday was announced:

local before = r.approved ~= nil and h.announced ~= nil and r.approved < h.announced
if not before then
ctx:book(d.date, 0)
end

Holidays that pay differently, such as regular holidays and special non-working days, are told apart as every holiday rule does: the step takes holidays = ["id", ...], and a second copy of it with the other ids treats them another way. Nothing new is added to a holiday for it.

Parameters

ParameterMeaning
holidaystrue (the default): every holiday the day observes; a list: those holidays.

What the scenarios show

  • approved-before-the-announcement-stays-charged: the holiday is announced on 1 October; the day was approved on 21 September, so its 8 hours stay charged, and a later request for 16 of the 16 hours is refused.
  • approved-after-the-announcement-is-not-charged: the same, approved on 2 October: the day draws nothing, and the later request for 16 stands.

Whether leave booked before a holiday was announced is charged is for the law where you operate and the contract that applies; this is only how to say it if it is yours.

Get the recipe

The recipe’s package and its scenarios are in the example packages repository: attendance/leave_charged_before_announcement. Test it, or your own copy of it, with hourctl attend test, and publish it with hourctl attend pkg publish.

The policy package

The package’s layers, with the standard steps each one runs and their settings:

leave_charged_before_announcement/package.toml
name = "leave_charged_before_announcement"
version = "1.0.0"
description = "Leave approved before a holiday was announced stays charged to the balance; leave approved after it draws nothing on the holiday: a business's own rule, written from the holiday's announcement and the leave's approval."
[needs]
accrual_categories = ["pto"]
[[layer]]
id = "charged-before-announcement"
[[layer.step]]
id = "holidays"
uses = "leave_charged_before_announcement/leave_charged_before_announcement"
params = {}
[[layer.step]]
id = "balance"
uses = "standard/leave_balance"
params = { balance = { vacation = "pto" } }
[[layer.step]]
id = "holiday"
uses = "standard/holiday_pay"
params = { time = "8h", category = "holiday" }

Steps of its own, for what no standard step does (write a policy step):

leave_charged_before_announcement/main.lua
-- A business's own rule, written from facts: leave that was approved before a
-- holiday was announced stays charged to the balance, and the holiday does
-- not take the day back; leave approved after the announcement draws
-- nothing on the holiday. The facts it reads: `ctx.request.approved` (when
-- the request was approved), `ctx:day(date).holidays[i].announced` (when the
-- holiday's date was first given), both instants in milliseconds.
local M = {}
local function named(list, id)
if list == true then
return true
end
for _, v in ipairs(list) do
if v == id then
return true
end
end
return false
end
M.leave_charged_before_announcement = {
stage = "leave",
params = {
holidays = { type = { "boolean", "list" }, of = "string", default = true },
},
run = function(ctx, p)
local r = ctx.request
for _, d in ipairs(r.days) do
local day = ctx:day(d.date)
for _, h in ipairs(day and day.holidays or {}) do
if d.time > 0 and named(p.holidays, h.id) then
-- Charged: approved, and before the date was announced.
local before = r.approved ~= nil and h.announced ~= nil and r.approved < h.announced
if not before then
ctx:book(d.date, 0)
end
break
end
end
end
end,
}
return M

Scenarios

Each scenario gives a person’s punches and setup and the timecard they must produce, worked out with this package adopted (the format).

Approved on 2 October, after the holiday was announced: the day draws nothing, 16 hours are left, and v2's 16 stands
scenarios/approved-after-the-announcement-is-not-charged.toml
description = "Approved on 2 October, after the holiday was announced: the day draws nothing, 16 hours are left, and v2's 16 stands"
[policy]
zone = "America/Chicago"
pay_periods = { month_days = [1] }
accruals = { since = "2026-09-01" }
[[category]]
id = "vacation"
worked = false
[[category]]
id = "holiday"
worked = false
[[accrual_category]]
id = "pto"
uses = ["vacation"]
# Announced on 1 October 2026.
[[holiday]]
id = "harvest"
name = "Harvest day"
month = 10
day = 8
announced = "2026-10-01T15:00:00Z"
[[accrual_adjustment]]
category = "pto"
workday = "2026-09-15"
amount = "16h"
recorded = "2026-09-15 09:00"
[[leave]]
id = "v1"
category = "vacation"
days = { "2026-10-08" = "8h" }
recorded = "2026-09-20 09:00"
[[approval]]
subject = "leave:v1:2026-10-08"
stage = "approval"
decision = "approve"
recorded = "2026-10-02 09:00"
[[leave]]
id = "v2"
category = "vacation"
days = { "2026-10-12" = "8h", "2026-10-13" = "8h" }
recorded = "2026-10-03 09:00"
[expect.period]
day = "2026-10-05"
leave = ["v1 approved", "v2 pending approval"]
Approved on 20 September, before the holiday of 8 October was announced (1 October): the day stays charged, 8 of the 16 hours, so v2's 16 would leave -8 and is refused
scenarios/approved-before-the-announcement-stays-charged.toml
description = "Approved on 20 September, before the holiday of 8 October was announced (1 October): the day stays charged, 8 of the 16 hours, so v2's 16 would leave -8 and is refused"
[policy]
zone = "America/Chicago"
pay_periods = { month_days = [1] }
accruals = { since = "2026-09-01" }
[[category]]
id = "vacation"
worked = false
[[category]]
id = "holiday"
worked = false
[[accrual_category]]
id = "pto"
uses = ["vacation"]
# Announced on 1 October 2026.
[[holiday]]
id = "harvest"
name = "Harvest day"
month = 10
day = 8
announced = "2026-10-01T15:00:00Z"
[[accrual_adjustment]]
category = "pto"
workday = "2026-09-15"
amount = "16h"
recorded = "2026-09-15 09:00"
[[leave]]
id = "v1"
category = "vacation"
days = { "2026-10-08" = "8h" }
recorded = "2026-09-20 09:00"
[[approval]]
subject = "leave:v1:2026-10-08"
stage = "approval"
decision = "approve"
recorded = "2026-09-21 09:00"
[[leave]]
id = "v2"
category = "vacation"
days = { "2026-10-12" = "8h", "2026-10-13" = "8h" }
recorded = "2026-10-03 09:00"
[expect.period]
day = "2026-10-05"
leave = ["v1 approved", "v2 refused: it would leave the pto balance below 0h"]