From ef1ee2647dd3c12575a1e16ad6d9741424143df4 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 7 Jan 2016 13:28:01 -0800 Subject: [PATCH] JBAS-1037 Kent/future expire dates 1. Set the expire age to 21 instead of 18 for Kent SD. 2. Ensure that no expire dates are set to before "now". Signed-off-by: Bill Erickson --- .../import_students/generate-patrons-from-csv.pl | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl b/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl index 55deee6592..4ec47fbaa7 100755 --- a/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl +++ b/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl @@ -24,6 +24,7 @@ my $c_alert_msg = 'Classroom use only: No physical checkouts. No computer/pr my $alert2_msg = 'DO NOT MERGE OR EDIT. RECORD MANAGED CENTRALLY.'; my $alert_type = 20; # "Alerting note, no Blocks" standing penalty my $root_org = 1; # KCLS org unit for penalty application +my $expire_age = 18; # Kent (for now) uses 21. my $db_handle; my %new_barcodes; my @failures; # one row per student account that failed for any reason @@ -158,7 +159,7 @@ sub announce { my ($level, $msg, $die) = @_; syslog("LOG_$level", $msg); - my $date_str = DateTime->now->strftime('%F %T'); + my $date_str = DateTime->now(time_zone => 'local')->strftime('%F %T'); my $msg_str = "$date_str [$$] $level $msg\n"; if ($die) { @@ -185,6 +186,9 @@ sub verify_options { die "Valid --commit-mode values are 'batch', 'rollback', and 'each'\n" unless $commit_mode =~ /^(batch|rollback|each)$/; + # Kent students may be as old as 21. + $expire_age = 21 if $district_code eq '415'; + if ($purge_all) { print "\nPurge every user in the CSV file? This is irreversible!\n"; print "Are you sure? [yes|no]\n"; @@ -279,7 +283,8 @@ SQL %new_barcodes = map {$_->[0] => 1} @$new_barcodes; } -# expire date is set to July 1 after the patron's 18th birthday. +# Expire date is set to July 1 after the patron's 18th birthday. +# Kent students (code 415) expire after 21st birthday. sub set_expire_date { my $phash = shift; my $now_date = DateTime->now; @@ -293,28 +298,38 @@ sub set_expire_date { } my ($year, $mon, $day) = ($phash->{dob} =~ /(\d{4})-(\d{2})-(\d{2})/); - my $expire_year = $now_year + (18 - ($now_year - $year)); + my $expire_year = $now_year + ($expire_age - ($now_year - $year)); # Invalid DoB's can lead to expire_date's far in the future. # If a student's birth year puts them at less than 2 years old, # modify the year to make them appear 2 years old for calculating # the expire year. We retain the provided day and month. - $expire_year = ($now_year + 16) if ($expire_year - $now_year) > 16; + my $max_expire = $expire_age - 2; + $expire_year = ($now_year + $max_expire) + if ($expire_year - $now_year) > $max_expire; # if dob occurs after july 1, expire date will occur the following year. $expire_year++ if ($mon > 7) or ($mon == 7 and $day > 1); - # Set hour to 6 to reduce likelyhood of DST/timezone + # Set hour to 6 to reduce likelihood of DST/timezone # confusion causing day-off-by-one issues with external clients. my $expire_date = DateTime->new( year => $expire_year, month => 7, day => 1, hour => 6, time_zone => 'local'); + + # If the student is older than expire_age, causing the expire + # date to be earlier than "now", set the expire date to the + # next occurrence of July 1. + if ($expire_date < $now_date) { + $expire_date->set_year( + $now_date->month < 7 ? $now_year : $now_year + 1); + } $phash->{expire_date} = $expire_date; } # Fills in gaps and massages data in the CSV hash. -# Returns 1 on successful translation, undef on error.qw/student_id first_given_name family_name dob/) { +# Returns 1 on successful translation, undef on error. sub translate_patron_data { my $phash = shift; my $barcode = $phash->{barcode}; -- 2.11.0