Pārlūkot izejas kodu

HUE-5186 [core] Get rid of deprecation warnings for Moment.js

Enrico Berti 9 gadi atpakaļ
vecāks
revīzija
b9e57c0d3a

+ 8 - 2
desktop/core/src/desktop/templates/common_header.mako

@@ -220,8 +220,14 @@ if USE_NEW_EDITOR.get():
       if (typeof ko !== 'undefined' && ko.isObservable(time)) {
         mTime = time();
       }
-      if (moment(mTime).isValid()) {
-        return moment.utc(mTime).format("L LT");
+      try {
+        mTime = new Date(mTime);
+        if (moment(mTime).isValid()) {
+          return moment.utc(mTime).format("L LT");
+        }
+      }
+      catch (e) {
+        return mTime;
       }
       return mTime;
     }

+ 8 - 2
desktop/core/src/desktop/templates/common_header_m.mako

@@ -163,8 +163,14 @@ if USE_NEW_EDITOR.get():
       if (typeof ko !== 'undefined' && ko.isObservable(time)) {
         mTime = time();
       }
-      if (moment(mTime).isValid()) {
-        return moment.utc(mTime).format("L LT");
+      try {
+        mTime = new Date(mTime);
+        if (moment(mTime).isValid()) {
+          return moment.utc(mTime).format("L LT");
+        }
+      }
+      catch (e) {
+        return mTime;
       }
       return mTime;
     }

+ 12 - 2
desktop/core/src/desktop/templates/responsive.mako

@@ -427,10 +427,20 @@ ${ assist.assistPanel() }
 
   moment.locale(window.navigator.userLanguage || window.navigator.language);
   localeFormat = function (time) {
+    var mTime = time;
     if (typeof ko !== 'undefined' && ko.isObservable(time)) {
-      return moment(time()).format("L LT");
+      mTime = time();
     }
-    return moment(time).format("L LT");
+    try {
+      mTime = new Date(mTime);
+      if (moment(mTime).isValid()) {
+        return moment.utc(mTime).format("L LT");
+      }
+    }
+    catch (e) {
+      return mTime;
+    }
+    return mTime;
   }
 
   // Add CSRF Token to all XHR Requests