Browse Source

HUE-7793 [dashboard] Do not convert dates with non traditional format (#676)

Tamas Sule 7 years ago
parent
commit
36493b96e7
1 changed files with 14 additions and 1 deletions
  1. 14 1
      desktop/libs/dashboard/src/dashboard/templates/common_search.mako

+ 14 - 1
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -3097,6 +3097,19 @@ function getPrettyMetric(facet) {
   }
 }
 
+// if the date separator is a dot and there's no 4 digit year at either end we invalidate it because it's most likely a version
+function getParsedDate(date) {
+  var parsedDate = moment(date);
+
+  if (parsedDate.isValid()) {
+    var splits = date.split('.');
+    if (splits.length === 3 && (splits[0].length !== 4 && splits[2].length !== 4)) {
+      return moment.invalid(date);
+    }
+  }
+  return parsedDate;
+}
+
 function prettifyDate(from, widget, to) {
   if (typeof from == "undefined" || $.isNumeric(from)) {
     return from;
@@ -3104,7 +3117,7 @@ function prettifyDate(from, widget, to) {
   if (typeof to != "undefined" && !$.isNumeric(to)) {
     return prettifyDateRange(from, to, widget);
   }
-  var _mFrom = moment(from);
+  var _mFrom = getParsedDate(from);
   if (_mFrom.isValid()) {
     var _format = "YYYY-MM-DD HH:mm:ss";
     var _minMaxDiff = 0;