Advertisement
chrissharp123

Untitled

Aug 5th, 2020
1,708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DECLARE
  2.     proper_tz TEXT := COALESCE(
  3.         oils_json_to_text((
  4.             SELECT value
  5.               FROM  actor.org_unit_ancestor_setting('lib.timezone',NEW.circ_lib)
  6.               LIMIT 1
  7.         )),
  8.         CURRENT_SETTING('timezone')
  9.     );
  10. BEGIN
  11.      
  12.     IF (EXTRACT(EPOCH FROM NEW.duration)::INT % EXTRACT(EPOCH FROM '1 day'::INTERVAL)::INT) = 0 -- day-granular duration            
  13.         AND SUBSTRING((NEW.due_date AT TIME ZONE proper_tz)::TIME::TEXT FROM 1 FOR 8) <> '23:59:59' THEN -- has not yet been pushed
  14.         NEW.due_date = ((NEW.due_date AT TIME ZONE proper_tz)::DATE + '1 day'::INTERVAL - '1 second'::INTERVAL) || ' ' || proper_tz;
  15.     END IF;
  16.      
  17.     RETURN NEW;
  18. END;  
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement