Commit ee562270 authored by Frank Bergmann's avatar Frank Bergmann

- Added a workday count based on a formula rather then on an iteration

parent 40c87f36
......@@ -247,6 +247,27 @@ begin
end;$body$ LANGUAGE 'plpgsql' VOLATILE;
-- Returns just the number of working days between two dates
CREATE or REPLACE FUNCTION im_resource_mgmt_workday_count (date, date)
RETURNS integer AS $BODY$
SELECT
($1 < $2)::int * (
to_char($2, 'J')::integer - to_char($1, 'J')::integer -
((($2 - $1) / 7) * 2 +
(EXTRACT(dow FROM $1)<6 AND EXTRACT(dow FROM $2)>0 AND EXTRACT(dow FROM $1)>EXTRACT(dow FROM $2))::int * 2 +
(EXTRACT(dow FROM $1)=6 AND EXTRACT(dow FROM $2)>0)::int +
(EXTRACT(dow FROM $2)=0 AND EXTRACT(dow FROM $1)<6)::int)
);
$BODY$
LANGUAGE 'sql' IMMUTABLE STRICT;
select im_resource_mgmt_workday_count('2018-05-01'::date, '2018-05-31'::date);
-- Returns the work days for a given period
-- whereas: "work days" = Number of days in period -absences -bank_holidays -weekends
-- Expects start_date and end_date as YYYY/MM/DD
......@@ -277,6 +298,7 @@ end;$body$ LANGUAGE 'plpgsql' VOLATILE;
-- Returns a real[] for each day between start and end
-- with 100 for working days and 0 for weekends
create or replace function im_resource_mgmt_weekend (integer, date, date)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment