[freeside-commits] freeside/FS/FS/UI Web.pm,1.26,1.27

Jeff Finucane,420,, jeff at wavetail.420.am
Wed Apr 11 20:16:44 PDT 2007


Update of /home/cvs/cvsroot/freeside/FS/FS/UI
In directory wavetail:/tmp/cvs-serv7777/FS/FS/UI

Modified Files:
	Web.pm 
Log Message:
input and output on data volume fields specified with k,m,g,or t

Index: Web.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/UI/Web.pm,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- Web.pm	14 Feb 2007 08:48:36 -0000	1.26
+++ Web.pm	12 Apr 2007 03:16:42 -0000	1.27
@@ -4,6 +4,7 @@
 use vars qw($DEBUG $me);
 use FS::Conf;
 use FS::Record qw(dbdef);
+use Number::Format;
 
 #use vars qw(@ISA);
 #use FS::UI
@@ -186,6 +187,31 @@
   return(sprintf("%.2f Gbytes", $bc/1000000000));
 }
 
+sub parse_bytecount {
+  my $bc = shift;
+  return $bc if (($bc =~ tr/.//) > 1);
+  $bc =~ /^\s*([\d.]*)\s*([kKmMgGtT]?)[bB]?\s*$/ or return $bc;
+  my $base = $1;
+  return $bc unless length $base;
+  my $exponent = index ' kmgt', lc($2);
+  return $bc if ($exponent < 0 && $2);
+  $exponent = 0 if ($exponent < 0);
+  return $base * 1024 ** $exponent;
+}
+
+sub display_bytecount {
+  my $bc = shift;
+  return $bc unless ($bc =~ /^(\d+)$/);
+  my $conf = new FS::Conf;
+  my $f = new Number::Format;
+  my $precision = $conf->exists('datavolume-significantdigits')
+                ? $conf->config('datavolume-significantdigits')
+                : 3;
+  my $unit = $conf->exists('datavolume-forcemegabytes') ? 'M' : 'A';
+
+  return $f->format_bytes($bc, precision => $precision, unit => $unit);
+}
+
 ###
 # cust_main report subroutines
 ###



More information about the freeside-commits mailing list