NAME
DateTime::Event::Random - DateTime::Set extension for creating random datetimes.
SYNOPSIS
use DateTime::Event::Random;
# creates a set of random dates
# with an average density of 4 months,
# that is, 3 events per year, with a span
# of 2 years
my $rand = DateTime::Event::Random->new(
months => 4,
start => DateTime->new( year => 2003 ),
end => DateTime->new( year => 2005 ),
);
print "next is ", $rand->next( DateTime->today )->datetime, "\n";
# output: next is 2004-02-29T22:00:51
@days = $rand->as_list;
print "days ", 1 + $#days, "\n";
# output: days 8
# - we expect a number near 6
print join('; ', map{ $_->datetime } @days );
# output: 2003-02-16T21:08:58; 2003-02-18T01:24:13; ...
DESCRIPTION
This module provides convenience methods that let you easily create DateTime::Set
objects with random datetimes.
USAGE
new
Returns a
DateTime::Set
object representing the set of random events.my $random_set = DateTime::Event::Random->new;
The set members occur at an average of once a day, forever.
You may give density parameters to change this:
my $two_daily_set = DateTime::Event::Random->new( days => 2 ); my $three_weekly_set = DateTime::Event::Random->new( weeks => 3 );
If span parameters are given, then the set is limited to the span:
my $rand = DateTime::Event::Random->new( months => 4, start => DateTime->new( year => 2003 ), end => DateTime->new( year => 2005 ), );
new_cached
Returns a
DateTime::Set
object representing the set of random events.Unbounded random sets are generated on demand, which means that the datetime values would not be repeateable between iterations.
If a set is created with
new_cached
, then once an event is seen, it is cached, such that all sequences extracted from the set are equal.my $random_set = DateTime::Event::Random->new_cached;
Cached sets are slower and take more memory than sets generated with the plain
new
constructor. It should only be used if you need unbounded sets that would be accessed many times and that need repeatable results.
NOTES
The module does not allow for repetition of values. That is, a function like next($dt)
will always return a value bigger than $dt
. Each element in a set is different.
Although the datetime values are random, the accessors (as_list
, iterator/next/previous
) always return sorted datetimes.
The module calculates all intervals in seconds, which may give a 32-bit integer overflow if you ask for a density less than about "1 occurence in each 30 years" - which is about a billion seconds. This may change in a next version.
AUTHOR
Flavio Soibelmann Glock fglock@pucrs.br
COPYRIGHT
Copyright (c) 2003 Flavio Soibelmann Glock. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
SEE ALSO
datetime@perl.org mailing list
DateTime Web page at http://datetime.perl.org/
DateTime - date and time :)
DateTime::Set - for recurrence-set accessors docs.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 212:
You forgot a '=back' before '=head1'