From 0b01a89cc8901ad0217455563c58b26c10f6dad7 Mon Sep 17 00:00:00 2001 From: "myk%mozilla.org" <> Date: Fri, 6 Feb 2004 02:14:01 +0000 Subject: Fix for bug 127995: shows the size of attachments in the show bug and attachment interfaces. Patch by Dave Swegen r=myk a=myk --- Bugzilla/Template.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Bugzilla/Template.pm') diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index d370627d3..c123154bb 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -258,6 +258,30 @@ sub create { return $var; } , + # Format a filesize in bytes to a human readable value + unitconvert => sub + { + my ($data) = @_; + my $retval = ""; + my %units = ( + 'KB' => 1024, + 'MB' => 1024 * 1024, + 'GB' => 1024 * 1024 * 1024, + ); + + if ($data < 1024) { + return "$data bytes"; + } + else { + my $u; + foreach $u ('GB', 'MB', 'KB') { + if ($data >= $units{$u}) { + return sprintf("%.2f %s", $data/$units{$u}, $u); + } + } + } + }, + # Format a time for display (more info in Bugzilla::Util) time => \&Bugzilla::Util::format_time, -- cgit v1.2.3-24-g4f1b