1 package IronMunger::Calculate;
6 use autobox::DateTime::Duration;
8 sub check_post_gap ($aperture, $days, @posts) {
9 return @posts if @posts <= $aperture;
10 my @next_post = splice(@posts, 0, $aperture);
11 return 0 if DateTime->now - $next_post[-1]->at > $days->days;
12 my $success = $aperture;
13 foreach my $post (@posts) {
14 return $success if $next_post[0]->at - $post->at > $days->days;
17 push(@next_post, $post);
22 sub check_time_remaining ($aperture, $days, @posts) {
23 my $cand = (@posts > $aperture ? $posts[$aperture - 1] : $posts[-1]);
24 return $days->days - (DateTime->now - $cand->at)->in_units('days');
27 sub successful_sequential_posts (@posts) {
29 check_post_gap(1, 10, @posts), # 10 days between posts
30 check_post_gap(3, 32, @posts), # 4 posts every 32 days