Fix missing expiring/expired icons and warnning messages in certificate table

- Confirmed with backend developer that we should be checking certificate expiration date with bmc date/time set
- Converted both certificate expiration date and bmc date/time to EPOCH time to fix the bug

Tested: Go to Date and Time settings and change BMC time to be after or 30 days before a certificate expiration date.
Then either a warning or expiration icon and message will be displayed next to the date and message on top of the table.
To remove the expiration or warning date, upload a certificate that has an expiration date greater than 30 days after bmc time
set. The icon and warning message should now disappear.

Signed-off-by: Mira Murali  <miramurali23@gmail.com>
Change-Id: I9389fe3cce5a555945adf9c56180897a6be047bf
diff --git a/app/configuration/controllers/certificate-controller.js b/app/configuration/controllers/certificate-controller.js
index cb22ac7..06b2fff 100644
--- a/app/configuration/controllers/certificate-controller.js
+++ b/app/configuration/controllers/certificate-controller.js
@@ -30,6 +30,10 @@
       $scope.countryList = Constants.COUNTRIES;
 
 
+      $scope.$on('$viewContentLoaded', () => {
+        getBmcTime();
+      })
+
       $scope.loadCertificates = function() {
         $scope.certificates = [];
         $scope.availableCertificateTypes = Constants.CERTIFICATE_TYPES;
@@ -97,9 +101,12 @@
       };
 
       var isExpiring = function(certificate) {
-        // if ValidNotAfter is less than or equal to 30 days from today
+        // convert certificate time to epoch time
+        // if ValidNotAfter is less than or equal to 30 days from bmc time
         // (2592000000), isExpiring. If less than or equal to 0, is expired.
-        var difference = certificate.ValidNotAfter - new Date();
+        // dividing bmc time by 1000 converts epoch milliseconds to seconds
+        var difference = (new Date(certificate.ValidNotAfter).getTime()) -
+            ($scope.bmcTime) / 1000;
         if (difference <= 0) {
           certificate.isExpired = true;
         } else if (difference <= 2592000000) {
@@ -200,6 +207,14 @@
       };
 
 
+      var getBmcTime = function() {
+        APIUtils.getBMCTime().then(function(data) {
+          $scope.bmcTime = data.data.Elapsed;
+        });
+
+        return $scope.bmcTime;
+      };
+
       var updateAvailableTypes = function(certificate) {
         // TODO: at this time only one of each type of certificate is allowed.
         // When this changes, this will need to be updated.
@@ -212,7 +227,8 @@
 
       $scope.getDays = function(endDate) {
         // finds number of days until certificate expiration
-        var ms = endDate - new Date();
+        // dividing bmc time by 1000 converts milliseconds to seconds
+        var ms = (new Date(endDate).getTime()) - ($scope.bmcTime) / 1000;
         return Math.floor(ms / (24 * 60 * 60 * 1000));
       };