my %MFHD_TAGS_BY_NAME = ( $MFHD_NAMES[0] => '853',
$MFHD_NAMES[1] => '854',
$MFHD_NAMES[2] => '855');
+my $_strp_date = new DateTime::Format::Strptime(pattern => '%F');
# helper method for conforming dates to ISO8601
sub _cleanse_dates {
my $options = {
'caption' => $caption_field,
'scap_id' => $scap->id,
- 'num_to_predict' => $args->{num_to_predict}
+ 'num_to_predict' => $args->{num_to_predict},
+ 'end_date' => defined $args->{end_date} ?
+ $_strp_date->parse_datetime($args->{end_date}) : undef
};
if ($args->{base_issuance}) { # predict from a given issuance
$options->{predict_from} = _revive_holding($args->{base_issuance}->holding_code, $caption_field, 1); # fresh MFHD Record, so we simply default to 1 for seqno
my $caption = $options->{caption};
my $scap_id = $options->{scap_id};
my $num_to_predict = $options->{num_to_predict};
+ my $end_date = $options->{end_date};
my $predict_from = $options->{predict_from}; # issuance to predict from
#my $last_rec_date = $options->{last_rec_date}; # expected or actual
# add a note marker for system use (?)
$predict_from->notes('private', ['AUTOGEN']);
- my $strp = new DateTime::Format::Strptime(pattern => '%F');
my $pub_date;
my @issuance_values;
- my @predictions = $mfhd->generate_predictions({'base_holding' => $predict_from, 'num_to_predict' => $num_to_predict});
+ my @predictions = $mfhd->generate_predictions({'base_holding' => $predict_from, 'num_to_predict' => $num_to_predict, 'end_date' => $end_date});
foreach my $prediction (@predictions) {
- $pub_date = $strp->parse_datetime($prediction->chron_to_date);
+ $pub_date = $_strp_date->parse_datetime($prediction->chron_to_date);
push(
@issuance_values,
{
my $class = ref($proto) || $proto;
my $self = shift;
+ $self->{_strp_date} = new DateTime::Format::Strptime(pattern => '%F');
+
$self->{_mfhd_CAPTIONS} = {};
$self->{_mfhd_COMPRESSIBLE} = (substr($self->leader, 17, 1) =~ /[45]/);
values %{$self->{_mfhd_HOLDINGS}->{$field}->{$capid}};
}
+sub _holding_date {
+ my $self = shift;
+ my $holding = shift;
+
+ return $self->{_strp_date}->parse_datetime($holding->chron_to_date);
+}
+
#
# generate_predictions()
# Accepts a hash ref of options initially defined as:
# num_to_predict : the number of issues you wish to predict
# OR
# end_holding : holding field ref, keep predicting until you meet or exceed it
+# OR
+# end_date : keep predicting until you exceed this
#
# The basic method is to first convert to a single holding if compressed, then
# increment the holding and save the resulting values to @predictions.
my $base_holding = $options->{base_holding};
my $num_to_predict = $options->{num_to_predict};
my $end_holding = $options->{end_holding};
+ my $end_date = $options->{end_date};
my $max_to_predict = $options->{max_to_predict} || 10000; # fail-safe
if (!defined($base_holding)) {
}
$next_holding = $curr_holding->increment->clone;
}
+ } elsif (defined($end_date)) {
+ my $next_holding = $curr_holding->increment->clone;
+ my $num_predicted = 0;
+ while ($self->_holding_date($next_holding) <= $end_date) {
+ push(@predictions, $next_holding);
+ $num_predicted++;
+ if ($num_predicted >= $max_to_predict) {
+ carp("Maximum prediction count exceeded");
+ last;
+ }
+ $next_holding = $curr_holding->increment->clone;
+ }
}
return @predictions;