Index: openacs-4/packages/ams/sql/postgresql/upgrade/upgrade-1.1d12-1.1d13.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/ams/sql/postgresql/upgrade/upgrade-1.1d12-1.1d13.sql,v
diff -u -N -r1.1 -r1.2
--- openacs-4/packages/ams/sql/postgresql/upgrade/upgrade-1.1d12-1.1d13.sql	30 Jan 2006 22:22:58 -0000	1.1
+++ openacs-4/packages/ams/sql/postgresql/upgrade/upgrade-1.1d12-1.1d13.sql	9 Feb 2006 23:30:03 -0000	1.2
@@ -82,3 +82,25 @@
 
         return v_address_id;
 end;' language 'plpgsql';
+
+
+create or replace function ams_util__next_instance_of_date(timestamptz)
+returns date as '
+declare
+        p_date          alias for $1;
+        v_years         integer;
+        v_next_instance date;
+begin
+
+    v_years := extract(year from now()) - extract(year from p_date);
+
+    v_next_instance := p_date + (v_years::varchar || '' years'')::interval;
+
+    -- if this already happend we and one more year
+    if v_next_instance::date < now()::date then
+        v_next_instance := v_next_instance + ''1 year''::interval;
+    end if;
+
+    return v_next_instance;
+end;' language 'plpgsql';
+
