]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/Common.pm
- Indicate date of last activity (closes: #207065)
[debbugs.git] / Debbugs / Common.pm
index 9776392eef2c7fc307f4fc442a18c233d46a4f15..60e2c3092adbb312dba3bc7c516fca748671ed4e 100644 (file)
@@ -43,11 +43,12 @@ BEGIN{
                                qw(getmaintainers_reverse)
                               ],
                     misc   => [qw(make_list)],
+                    date   => [qw(secs_to_english)],
                     quit   => [qw(quit)],
                     lock   => [qw(filelock unfilelock @cleanups)],
                    );
      @EXPORT_OK = ();
-     Exporter::export_ok_tags(qw(lock quit util misc));
+     Exporter::export_ok_tags(qw(lock quit date util misc));
      $EXPORT_TAGS{all} = [@EXPORT_OK];
 }
 
@@ -239,6 +240,32 @@ sub getmaintainers_reverse{
      return $_maintainer_rev;
 }
 
+=head1 DATE
+
+    my $english = secs_to_english($seconds);
+    my ($days,$english) = secs_to_english($seconds);
+
+XXX This should probably be changed to use Date::Calc
+
+=cut
+
+sub secs_to_english{
+     my ($seconds) = @_;
+
+     my $days = int($seconds / 86400);
+     my $years = int($days / 365);
+     $days -= $years * 365;
+     my $result;
+     my @age;
+     push @age, "1 year" if ($years == 1);
+     push @age, "$years years" if ($years > 1);
+     push @age, "1 day" if ($days == 1);
+     push @age, "$days days" if ($days > 1);
+     $result .= join(" and ", @age);
+
+     return wantarray?($days,$result):$result;
+}
+
 
 =head1 LOCK