FERLIX-3022 Add uptime information in addition to the start time.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1143664 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
index a700fb3..556b8bd 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
@@ -20,6 +20,8 @@
 
 
 import java.io.IOException;
+import java.text.DateFormat;
+import java.text.MessageFormat;
 import java.util.Date;
 
 import javax.servlet.ServletException;
@@ -55,7 +57,7 @@
     private static final String PARAM_SHUTDOWN_TYPE_RESTART = "Restart";
     //private static final String PARAM_SHUTDOWN_TYPE_STOP = "Stop";
 
-    private static final long startDate = ( new Date() ).getTime();
+    private static final long startDate = System.currentTimeMillis();
 
     // from BaseWebConsolePlugin
     private static String START_LEVEL_NAME = StartLevel.class.getName();
@@ -195,12 +197,17 @@
         if ( shutdownType == null )
             shutdownType = "";
 
+        DateFormat format = DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.LONG, request.getLocale() );
+        final String startTime = format.format( new Date( startDate ) );
+        final String upTime = formatPeriod( System.currentTimeMillis() - startDate );
+
         JSONObject json = new JSONObject();
         try
         {
             json.put( "systemStartLevel", getStartLevel().getStartLevel() );
             json.put( "bundleStartLevel", getStartLevel().getInitialBundleStartLevel() );
-            json.put( "lastStarted", startDate );
+            json.put( "lastStarted", startTime );
+            json.put( "upTime", upTime );
             json.put( "runtime", System.getProperty( "java.runtime.name" ) + "(build "
                 + System.getProperty( "java.runtime.version" ) + ")" );
             json.put( "jvm", System.getProperty( "java.vm.name" ) + "(build " + System.getProperty( "java.vm.version" )
@@ -230,6 +237,20 @@
     }
 
 
+    private String formatPeriod( final long period )
+    {
+        final Long msecs = new Long( period % 1000 );
+        final Long secs = new Long( period / 1000 % 60 );
+        final Long mins = new Long( period / 1000 / 60 % 60 );
+        final Long hours = new Long( period / 1000 / 60 / 60 % 24 );
+        final Long days = new Long( period / 1000 / 60 / 60 / 24 );
+        return MessageFormat.format(
+            "{0,number} '${vmstat.upTime.format.days}' {1,number,00}:{2,number,00}:{3,number,00}.{4,number,000}",
+            new Object[]
+                { days, hours, mins, secs, msecs } );
+    }
+
+
     private final StartLevel getStartLevel()
     {
         return ( StartLevel ) getService( START_LEVEL_NAME );
diff --git a/webconsole/src/main/native2ascii/OSGI-INF/l10n/bundle_de.properties b/webconsole/src/main/native2ascii/OSGI-INF/l10n/bundle_de.properties
index 7eb3050..019daff 100644
--- a/webconsole/src/main/native2ascii/OSGI-INF/l10n/bundle_de.properties
+++ b/webconsole/src/main/native2ascii/OSGI-INF/l10n/bundle_de.properties
@@ -56,6 +56,8 @@
 vmstat.sl.bundle=Default Bundle Start Level
 vmstat.info.title=Server Information:
 vmstat.lastStarted=Letzter Start
+vmstat.upTime=Betriebszeit
+vmstat.upTime.format.days=Tage
 vmstat.framework=Framework
 vmstat.shutdown.in=Stoppe in 
 vmstat.java.title=Java Information:
diff --git a/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties b/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
index f28be89..4eb754e 100644
--- a/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
+++ b/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
@@ -57,6 +57,8 @@
 vmstat.sl.bundle=Default Bundle Start Level
 vmstat.info.title=Server Information:
 vmstat.lastStarted=Last Started
+vmstat.upTime=Uptime
+vmstat.upTime.format.days=days
 vmstat.framework=Framework
 vmstat.shutdown.in=Shutdown in 
 vmstat.java.title=Java Information:
diff --git a/webconsole/src/main/resources/res/ui/vmstat.js b/webconsole/src/main/resources/res/ui/vmstat.js
index 684b68a..5ad9961 100644
--- a/webconsole/src/main/resources/res/ui/vmstat.js
+++ b/webconsole/src/main/resources/res/ui/vmstat.js
@@ -34,7 +34,6 @@
 			target.text(statData[i]);
 		}
 	}
-	$('#lastStarted').text(localTm(statData.lastStarted));
 	var st = statData.shutdownTimer;
 	$('#shutdownform').css('display', st ? 'none' : 'block');
 	$('#shutdownform2').css('display', st ? 'block' : 'none');
diff --git a/webconsole/src/main/resources/templates/vmstat.html b/webconsole/src/main/resources/templates/vmstat.html
index 0f8f984..0c2ad55 100644
--- a/webconsole/src/main/resources/templates/vmstat.html
+++ b/webconsole/src/main/resources/templates/vmstat.html
@@ -49,6 +49,10 @@
 		<td id="lastStarted">---</td>
 	</tr>
 	<tr>
+		<td>${vmstat.upTime}</td>
+		<td id="upTime">---</td>
+	</tr>
+	<tr>
 		<td>${vmstat.framework}</td>
 		<td>
 			<form id="shutdownform" method="post" action="${pluginRoot}">