Adding global.timezone org unit setting and config.timezone table to db and fm. user/jamesrf/timezone-patch
authorJames Fournie <jfournie@sitka.bclibraries.ca>
Wed, 6 Jun 2012 16:52:59 +0000 (09:52 -0700)
committerJames Fournie <jfournie@sitka.bclibraries.ca>
Thu, 1 Nov 2012 23:48:36 +0000 (16:48 -0700)
Modified Circulate.pm code to retrieve global.timezone setting when setting the
due date and push the due date to 23:59 in the correct timezone.

Note that a trigger on action.circulation still pushes the due date to 23:59
server time regardless, this will be fixed in a future patch.

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/090.schema.action.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/xxxx.schema.config_timezone.sql [new file with mode: 0644]

index 5b9725a..5a07144 100644 (file)
@@ -9301,6 +9301,18 @@ SELECT  usr,
                </permacrud>
        </class>
 
+       <class id="ctz" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="config::timezone" oils_persist:tablename="config.timezone" reporter:label="Timezones" oils_persist:field_safe="true">
+               <fields oils_persist:primary="name">
+                       <field reporter:label="Name" name="name" reporter:datatype="text"/>
+               </fields>
+               <links/>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+                       <actions>
+                               <retrieve/>
+                       </actions>
+               </permacrud>
+       </class>
+
        <class id="rlcd" controller="open-ils.cstore open-ils.pcrud open-ils.reporter-store" oils_obj:fieldmapper="reporter::last_copy_deleted" oils_persist:readonly="true" reporter:core="true" reporter:label="Last Copy Delete Time">
                <oils_persist:source_definition>
 
index 83a46a8..1476259 100644 (file)
@@ -2254,11 +2254,27 @@ sub create_due_date {
     # turn it into an interval that interval_to_seconds can parse
     $duration =~ s/(\d{2}):(\d{2}):(\d{2})/$1 h $2 m $3 s/o;
 
-    # for now, use the server timezone.  TODO: use workstation org timezone
-    my $due_date = DateTime->now(time_zone => 'local');
-
-    # add the circ duration
-    $due_date->add(seconds => OpenSRF::Utils->interval_to_seconds($duration));
+    # get time zone from org setting, failing that use local (server time zone)
+    my $tz = $U->ou_ancestor_setting_value($self->circ_lib, 'global.timezone') || 'local';
+
+    # set the due date to 'now' in that time zone
+    my $due_date = DateTime->now(time_zone => $tz);
+
+    # add the circ duration to get the actual due date
+    my $durationseconds = OpenSRF::Utils->interval_to_seconds($duration);
+    $due_date->add(seconds => OpenSRF::Utils->interval_to_seconds($durationseconds));
+
+    #push the due date to 23:59 (now in the local tz) for any loan that divides evenly into days
+    if($durationseconds % 86400 == 0){
+        $due_date = DateTime->new(
+            year      => $due_date->year,
+            month     => $due_date->month,
+            day       => $due_date->day,
+            hour      => 23,
+            minute    => 59,
+            time_zone => $tz,
+        );
+    }
 
     if($date_ceiling) {
         my $cdate = DateTime::Format::ISO8601->new->parse_datetime(cleanse_ISO8601($date_ceiling));
index e722361..c44aa94 100644 (file)
@@ -1001,5 +1001,7 @@ CREATE TABLE config.usr_activity_type (
 CREATE UNIQUE INDEX unique_wwh ON config.usr_activity_type 
     (COALESCE(ewho,''), COALESCE (ewhat,''), COALESCE(ehow,''));
 
+-- you probably want to delete entries from this table
+CREATE TABLE config.timezone AS SELECT name FROM pg_timezone_names;
 
 COMMIT;
index 1af6e89..8d61400 100644 (file)
@@ -172,18 +172,6 @@ CREATE TRIGGER mat_summary_create_tgr AFTER INSERT ON action.circulation FOR EAC
 CREATE TRIGGER mat_summary_change_tgr AFTER UPDATE ON action.circulation FOR EACH ROW EXECUTE PROCEDURE money.mat_summary_update ();
 CREATE TRIGGER mat_summary_remove_tgr AFTER DELETE ON action.circulation FOR EACH ROW EXECUTE PROCEDURE money.mat_summary_delete ();
 
-CREATE OR REPLACE FUNCTION action.push_circ_due_time () RETURNS TRIGGER AS $$
-BEGIN
-    IF (EXTRACT(EPOCH FROM NEW.duration)::INT % EXTRACT(EPOCH FROM '1 day'::INTERVAL)::INT) = 0 THEN
-        NEW.due_date = (NEW.due_date::DATE + '1 day'::INTERVAL - '1 second'::INTERVAL)::TIMESTAMPTZ;
-    END IF;
-
-    RETURN NEW;
-END;
-$$ LANGUAGE PLPGSQL;
-
-CREATE TRIGGER push_due_date_tgr BEFORE INSERT OR UPDATE ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.push_circ_due_time();
-
 CREATE OR REPLACE FUNCTION action.fill_circ_copy_location () RETURNS TRIGGER AS $$
 BEGIN
     SELECT INTO NEW.copy_location location FROM asset.copy WHERE id = NEW.target_copy;
index 5668078..c732c74 100644 (file)
@@ -3761,6 +3761,15 @@ INSERT into config.org_unit_setting_type
         'coust', 'description'),
     'string', null)
 
+,( 'global.timezone','glob',
+    oils_i18n_gettext('global.timezone',
+        'Timezone',
+        'coust', 'label'),
+    oils_i18n_gettext('global.timezone',
+        'Timezone to use for transaction processing',
+        'coust', 'description'),
+    'link', 'ctz')
+
 ,( 'gui.disable_local_save_columns', 'gui',
     oils_i18n_gettext('gui.disable_local_save_columns',
         'Disable the ability to save list column configurations locally.',
diff --git a/Open-ILS/src/sql/Pg/upgrade/xxxx.schema.config_timezone.sql b/Open-ILS/src/sql/Pg/upgrade/xxxx.schema.config_timezone.sql
new file mode 100644 (file)
index 0000000..a5ea9a2
--- /dev/null
@@ -0,0 +1,23 @@
+
+--SELECT evergreen.upgrade_deps_block_check('0712', :eg_version);
+
+BEGIN;
+
+DO $$BEGIN RAISE WARNING 'We are populating config.timezone with all timezones from pg_timezone_names. It is recommended that you manually delete any timezones that you don\'t need.'; END;$$;
+CREATE TABLE config.timezone AS SELECT name FROM pg_timezone_names;
+
+--DROP TRIGGER push_due_date_tgr ON action.circulation;
+--DROP FUNCTION action.push_circ_due_time();
+
+INSERT into config.org_unit_setting_type 
+    (name, grp, label, description, datatype) 
+    VALUES ( 'global.timezone','glob',
+    oils_i18n_gettext('global.timezone',
+        'Timezone',
+        'coust', 'label'),
+    oils_i18n_gettext('global.timezone',
+        'Timezone to use for transaction processing',
+        'coust', 'description'),
+    'link', 'ctz');
+
+COMMIT;