add better uptime calculation
[GitHub/Stricted/speedport-hybrid-php-api.git] / lib / trait / System.class.php
index 4cd4c6e3befb9c99cde0b1e4eecaa4dcbb9a618e..d0827ff73905df9e99a70df69d118a05158f2548 100644 (file)
@@ -6,15 +6,17 @@
  */
 trait System {
        /**
-        * get uptime based on online (connection) time
+        * get uptime based on last reboot
         *
         * @return      string
         */
        public function getUptime () {
-               $data = $this->getData('Overview');
-               $data = $this->getValues($data);
+               $lastReboot = $this->getLastReboot();
+               
+               $dtF = new DateTime("@0");
+               $dtT = new DateTime("@".$lastReboot);
                
-               return $data['days_online'];
+               return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds');
        }
        
        /**
@@ -50,6 +52,20 @@ trait System {
                }
        }
        
+       /**
+        * get Last Reboot time
+        * 
+        * @return      int
+        */
+       public function getLastReboot () {
+               $response = $this->sendRequest("data/Reboot.json");
+               $response = $this->getValues($response);
+
+               $lastReboot = time() - strtotime($response['reboot_date']." ".$response['reboot_time']);
+               
+               return $lastReboot;
+       }
+       
        /**
         * reset the router to Factory Default
         * not tested