View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Brian Hann > DateTime-Event-Predict > DateTime::Event::Predict



Annotate this POD

Module Version: 0.01_03   Source  


DateTime::Event::Predict - Predict new dates from a set of dates


Given a set of dates this module will predict the next date or dates to follow.

  use DateTime::Event::Predict;

  my $dtp = DateTime::Event::Predict->new(
      profile => {
          buckets => ['day_of_week'],

  # Add today's date: 2009-12-17
  my $date = new DateTime->today();

  # Add the previous 14 days
  for  (1 .. 14) {
      my $new_date = $date->clone->add(
          days => ($_ * -1),


  # Predict the next date
  my $predicted_date = $dtp->predict;

  print $predicted_date->ymd;

  # 2009-12-18

Here we create a new DateTime object with today's date (it being December 17th, 2009 currently). We then use add_date to add it onto the list of dates that DateTime::Event::Predict (DTP) will use to make the prediction.

Then we take the 14 previous days (December 16-2) and them on to same list one by one. This gives us a good set to make a prediction out of.

Finally we call predict which returns a DateTime object representing the date that DTP has calculated will come next.


Predicting the future is not easy, as anyone except, perhaps, Nostradamus will tell you. Events can occur with perplexing randomness and discerning any pattern in the noise is nigh unpossible.

However, if you have a set of data to work with that you know for certain contains some sort of regularity, and you have enough information to discover that regularity, then making predictions from that set can be possible. The main issue with our example above is the tuning we did with this sort of information.

When you configure your instance of DTP, you will have to tell what sorts of date-parts to keep track of so that it has a good way of making a prediction. Date-parts can be things like "day of the week", "day of the year", "is a weekend day", "week on month", "month of year", differences between dates counted by "week", or "month", etc. Dtpredict will collect these identifiers from all the provided dates into "buckets" for processing later on.


Predicting Easter




        my $dtp = DateTime::Event::Predict->new();


Arguments: none | \@dates

Return value: \@dates

Called with no argument this method will return an arrayref to the list of the dates currently in the instance.

Called with an arrayref to a list of DateTime objects (\@dates) this method will set the dates for this instance to \@dates.


Arguments: $date

Return value:

Adds a date on to the list of dates in the instance, where $date is a DateTime object.


Arguments: $profile

Set the profile for which date-parts will be

  # Pass in preset profile by its alias
  $dtp->profile( profile => 'default' );
  $dtp->profile( profile => 'holiday' );

  # Create a new profile
  my $profile = new DateTime::Event::Predict::Profile(
      buckets => [qw/ minute hour day_of_week day_of_month /],

  $dtp->profile( profile => $profile );

Provided profiles

The following profiles are provided for use by-name:


Arguments: %options

Return Value: $next_date | @next_dates

Predict the next date(s) from the dates supplied.

  my $predicted_date = $dtp->predict();

If list context predict returns a list of all the predictions, sorted by their probability:

  my @predicted_dates = $dtp->predict();

The number of prediction can be limited with the max_predictions option.

Possible options

      max_predictions => 4, # Once 4 predictions are found, return back
      callbacks => [
          sub { return ($_->second % 4) ? 0 : 1 } # Only predict dates with second values that are divisible by four.

Maximum number of predictions to find.


Arrayref of subroutine callbacks. If any of them return a false value the date will not be returned as a prediction.


Train this instance of DTP



Brian Hann, <brian.hann at>


Please report any bugs or feature requests to bug-datetime-event-predict at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc DateTime::Event::Predict

You can also look for information at:


Copyright 2009 Brian Hann, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


DateTime, DateTime::Event::Predict::Profile

syntax highlighting: