From: James Fournie Date: Wed, 6 Jun 2012 16:52:59 +0000 (-0700) Subject: Adding global.timezone org unit setting and config.timezone table to db and fm. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=61cb6758e5d44ab696d6dac019c94247fb72c849;p=working%2FEvergreen.git Adding global.timezone org unit setting and config.timezone table to db and fm. 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. --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 5b9725a6b0..5a071447ed 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -9301,6 +9301,18 @@ SELECT usr, + + + + + + + + + + + + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm index 83a46a84d5..1476259eff 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm @@ -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)); diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index e722361130..c44aa94965 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -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; diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql index 1af6e89ead..8d61400142 100644 --- a/Open-ILS/src/sql/Pg/090.schema.action.sql +++ b/Open-ILS/src/sql/Pg/090.schema.action.sql @@ -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; diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 5668078c5d..c732c740eb 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -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 index 0000000000..a5ea9a2e82 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/xxxx.schema.config_timezone.sql @@ -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;