--
-- timezone__get_offset/2
--
create or replace function timezone__get_offset(
  p_tz_id integer,
  p_time timestamp with time zone
) returns interval as $$

DECLARE
  v_offset integer;
BEGIN
  v_offset := '0';

  select gmt_offset into v_offset
  from timezone_rules
  where  tz_id = p_tz_id and p_time between utc_start and utc_end;

  return "interval" (v_offset || 'seconds');
END;
$$ language plpgsql;