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
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) {
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";
%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;
}
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};