switch day diff calculation to epoch based so that "N hours short of M days" becomes...
[engit/Iron-Munger.git] / lib / IronMunger / Calculate.pm
index ab01eca..236953f 100644 (file)
@@ -9,14 +9,17 @@ use signatures;
 
 use Sub::Exporter -setup => {
   exports => [
-    qw(successful_sequential_posts days_remaining_to_post)
+    qw(successful_sequential_posts days_remaining_to_post level_for_post_count)
   ]
 };
 
 sub day_diff ($dt1, $dt2) {
   $dt1 = $dt1->at if $dt1->isa('IronMunger::Post');
   $dt2 = $dt2->at if $dt2->isa('IronMunger::Post');
-  $dt1->delta_days($dt2)->delta_days;
+  my $seconds = $dt2->epoch - $dt1->epoch;
+  $seconds = -$seconds if $seconds < 0;
+  int($seconds / 86400);
+  #$dt1->delta_days($dt2)->delta_days;
 }
 
 sub check_post_gap ($aperture, $days, @posts) {
@@ -64,4 +67,11 @@ sub days_remaining_to_post (@posts) {
   return check_both(\&check_time_remaining, @posts);
 }
 
+sub level_for_post_count($count) {
+  return 'paper' if $count < 4;
+  return 'stone' if $count < 12;
+  return 'bronze' if $count < 36;
+  return 'iron';
+}
+
 1;