Files
mip/Data/BulkLoad/EFT/Nominations/plsql/hours_in_gas_day.fnc

66 lines
1.9 KiB
Plaintext

CREATE OR REPLACE FUNCTION EFT_NOM.hours_in_gas_day( p_gas_day IN DATE )
RETURN NUMBER
IS
/**
-- FUNCTION check_hours_in_gas_day --
-- Returns number of hours for the given gas day
-- Required for Daylight Saving checks where the hours in a day can be 23 or 25
--
-- %param p_gas_day The date being checked (This MUST be provided in local time NOT gmt)
--
-- %return NUMBER. Number of hours in the given gas day
--
-- Note: The gas day given is assumed to be the 6am START of the gas day being checked.
*/
l_hours NUMBER := 0;
l_temp_date DATE;
l_gmt_hour_today NUMBER := -1;
l_gmt_hour_yesterday NUMBER := -1;
l_gas_day_offset NUMBER;
BEGIN
l_hours := -1;
l_temp_date := TRUNC(p_gas_day + 1);
l_gas_day_offset := NVL(cout_system_configuration.get_configuration_item('GAS_DAY_OFFSET'),6);
BEGIN
SELECT TO_CHAR( translate_date( TRUNC(l_temp_date) + (l_gas_day_offset/24) ), 'HH24' )
INTO l_gmt_hour_today
FROM dual;
EXCEPTION
WHEN others THEN
l_gmt_hour_today := -1;
END;
BEGIN
SELECT TO_CHAR( translate_date( TRUNC(l_temp_date) + (l_gas_day_offset/24) - 1 ), 'HH24' )
INTO l_gmt_hour_yesterday
FROM dual;
EXCEPTION
WHEN others THEN
l_gmt_hour_yesterday := -1;
END;
IF l_gmt_hour_today != -1
AND l_gmt_hour_yesterday != -1
THEN
IF l_gmt_hour_today = l_gmt_hour_yesterday
THEN
-- 24 hours today....
l_hours := 24;
ELSIF l_gmt_hour_today < l_gmt_hour_yesterday
THEN
-- 23 Hours in the day.....
l_hours := 23;
ELSE
-- l_gmt_hour_today > l_gmt_hour_yesterday
-- 25 Hours in the day.....
l_hours := 25;
END IF;
END IF;
RETURN l_hours;
END hours_in_gas_day;
/