CREATE OR REPLACE FUNCTION food600.uzav_old2new(
	o_uzav character varying)
    RETURNS character varying
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE
AS $BODY$
declare
new_uzav character varying;
begin

 IF char_length(btrim(o_uzav))=12 then
	new_uzav='20' || btrim(o_uzav)||':00';
 ELSE 
	new_uzav = food600.LEFT(o_uzav, 17);
 END IF; 

new_uzav = 
CASE WHEN strpos(o_uzav,'*') <> 0 AND char_length(o_uzav)>12 THEN substring(new_uzav from 1 for 11) || '*' || substring(new_uzav from 13 for 5)
     WHEN strpos(o_uzav,'#') <> 0 AND char_length(o_uzav)>12 THEN substring(new_uzav from 1 for 11) || '#' || substring(new_uzav from 13 for 5)
     ELSE new_uzav
END;

RETURN new_uzav;
end;
$BODY$;
