Files
ems/db/routines/R__fn_planning_slot_boundary_prague.sql
Dusan Vojacek 93f883f5e0
Some checks failed
CI and deploy / migration-check (push) Successful in 5s
CI and deploy / deploy (push) Failing after 20s
sql first refactor
2026-04-19 20:02:20 +02:00

21 lines
783 B
SQL

-- začátek aktuálního (+offset) 15min slotu v Europe/Prague jako timestamptz (UTC instants)
create or replace function ems.fn_planning_slot_boundary_prague(p_offset_slots int default 0)
returns timestamptz
language sql
stable
as $fn$
select (
(date_trunc('day', loc.ts)
+ make_interval(
hours => extract(hour from loc.ts)::int,
mins => (floor(extract(minute from loc.ts) / 15) * 15)::int
)
)::timestamp at time zone 'Europe/Prague'
) + make_interval(mins => coalesce(p_offset_slots, 0) * 15)
from (select now() at time zone 'Europe/Prague' as ts) loc;
$fn$;
comment on function ems.fn_planning_slot_boundary_prague(int) is
'Začátek 15min slotu v časové zóně site provozu (Europe/Prague floor); offset v násobcích 15 min.';