This is an automated email from the ASF dual-hosted git repository. ppawar pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/branch-2.0 by this push: new f2afb2919 ATLAS-4732:UI: Setting 'atlas.ui.date.format' to certain value creates incorrect date entries f2afb2919 is described below commit f2afb2919e23369e64112599cea19136b3225a8b Author: Prasad Pawar <prasad.pa...@freestoneinfotech.com> AuthorDate: Wed Apr 5 11:07:47 2023 +0530 ATLAS-4732:UI: Setting 'atlas.ui.date.format' to certain value creates incorrect date entries Signed-off-by: Prasad Pawar <prasad.pa...@cloudera.com> --- dashboardv2/public/js/main.js | 5 +++-- dashboardv2/public/js/utils/CommonViewFunction.js | 6 +++--- dashboardv2/public/js/utils/Globals.js | 1 + dashboardv2/public/js/utils/Utils.js | 10 ++++++++++ .../public/js/views/entity/EntityBusinessMetaDataItemView.js | 6 ++++-- dashboardv2/public/js/views/tag/AddTagModalView.js | 3 ++- dashboardv2/public/js/views/tag/AddTimezoneItemView.js | 3 ++- dashboardv3/public/js/main.js | 7 ++++--- dashboardv3/public/js/utils/CommonViewFunction.js | 6 +++--- dashboardv3/public/js/utils/Globals.js | 1 + dashboardv3/public/js/utils/Utils.js | 10 ++++++++++ .../public/js/views/entity/EntityBusinessMetaDataItemView.js | 6 ++++-- dashboardv3/public/js/views/tag/AddTagModalView.js | 5 +++-- dashboardv3/public/js/views/tag/AddTimezoneItemView.js | 3 ++- 14 files changed, 52 insertions(+), 20 deletions(-) diff --git a/dashboardv2/public/js/main.js b/dashboardv2/public/js/main.js index 7c1332404..f0cea7999 100644 --- a/dashboardv2/public/js/main.js +++ b/dashboardv2/public/js/main.js @@ -286,6 +286,7 @@ require(['App', } if (response['atlas.ui.date.format'] !== undefined) { Globals.dateTimeFormat = response['atlas.ui.date.format']; + if (Globals.dateTimeFormat.toLocaleLowerCase().indexOf("dd") == 0) Globals.needToValidateDate = true; var dateFormatSeperated = Globals.dateTimeFormat.split(' '); if (dateFormatSeperated[0]) { Globals.dateFormat = dateFormatSeperated[0]; //date @@ -301,10 +302,10 @@ require(['App', Globals.isTasksEnabled = response['atlas.tasks.enabled']; } if (response['atlas.session.timeout.secs']) { Globals.idealTimeoutSeconds = response['atlas.session.timeout.secs']; } - if(response['atlas.lineage.on.demand.enabled'] !== undefined){ + if (response['atlas.lineage.on.demand.enabled'] !== undefined) { Globals.isLineageOnDemandEnabled = response['atlas.lineage.on.demand.enabled']; } - if(response['atlas.lineage.on.demand.default.node.count'] !== undefined){ + if (response['atlas.lineage.on.demand.default.node.count'] !== undefined) { Globals.lineageNodeCount = response['atlas.lineage.on.demand.default.node.count']; } /* Atlas idealTimeout diff --git a/dashboardv2/public/js/utils/CommonViewFunction.js b/dashboardv2/public/js/utils/CommonViewFunction.js index 727dc2c6b..ff05ed75b 100644 --- a/dashboardv2/public/js/utils/CommonViewFunction.js +++ b/dashboardv2/public/js/utils/CommonViewFunction.js @@ -635,14 +635,14 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum url = [(obj.id || obj.attributeName), mapApiOperatorToUI(obj.operator), value]; if (obj.operator === "TIME_RANGE") { if (value.indexOf("-") > -1) { - url[2] = value.split('-').map(function(udKey) { - return Date.parse(udKey.trim()).toString() + url[2] = value.split(' - ').map(function(udKey) { + return Globals.needToValidateDate ? Date.parse(Utils.convertToValidDate(udKey.trim())).toString() : Date.parse(udKey.trim()).toString(); }).join(",") } else { url[2] = Enums.queryBuilderDateRangeUIValueToAPI[_.trim(value)] || value; } } else if (value && value.length && type === 'date' && formatedDateToLong) { - url[2] = Date.parse(value); + url[2] = Globals.needToValidateDate ? Date.parse(Utils.convertToValidDate(value)) : Date.parse(value); } if (type) { url.push(type); diff --git a/dashboardv2/public/js/utils/Globals.js b/dashboardv2/public/js/utils/Globals.js index 0733f9424..431a24b38 100644 --- a/dashboardv2/public/js/utils/Globals.js +++ b/dashboardv2/public/js/utils/Globals.js @@ -49,6 +49,7 @@ define(["require", "underscore"], function(require, _) { // Date Format Globals.dateTimeFormat = "MM/DD/YYYY hh:mm:ss A"; Globals.dateFormat = "MM/DD/YYYY"; + Globals.needToValidateDate = false; Globals.isTimezoneFormatEnabled = true; Globals.isDebugMetricsEnabled = false; diff --git a/dashboardv2/public/js/utils/Utils.js b/dashboardv2/public/js/utils/Utils.js index 106fb7bd3..25ce3190e 100644 --- a/dashboardv2/public/js/utils/Utils.js +++ b/dashboardv2/public/js/utils/Utils.js @@ -939,6 +939,16 @@ define(['require', 'utils/Globals', 'pnotify', 'utils/Messages', 'utils/Enums', $(this).removeClass('button-loader').removeAttr("disabled"); $(this).siblings("button.cancel").prop("disabled", false); } + Utils.convertToValidDate = function(dateValue) { + var value = dateValue.split(" "), + dateSplit = (value[0].indexOf("-") == -1) ? value[0].split("/") : value[0].split("-"); + if (value.length > 1) { + var time = value[1].split(":"); + return new Date(dateSplit[2], (new Number(dateSplit[1]) - 1), dateSplit[0], time[0], time[1], time[2]); + } else { + return new Date(dateSplit[2], (new Number(dateSplit[1]) - 1), dateSplit[0]); + } + } Utils.formatDate = function(options) { var dateValue = null, dateFormat = Globals.dateTimeFormat, diff --git a/dashboardv2/public/js/views/entity/EntityBusinessMetaDataItemView.js b/dashboardv2/public/js/views/entity/EntityBusinessMetaDataItemView.js index 3169c7b3d..76c748d1d 100644 --- a/dashboardv2/public/js/views/entity/EntityBusinessMetaDataItemView.js +++ b/dashboardv2/public/js/views/entity/EntityBusinessMetaDataItemView.js @@ -148,12 +148,14 @@ define(['require', dateStr = []; if (dateValues.length) { _.each(dateValues, function(selectedDate) { - dateStr.push(new Date(selectedDate.trim()).getTime()); + var convertedDate = Globals.needToValidateDate ? Utils.convertToValidDate(selectedDate.trim()).getTime() : new Date(selectedDate.trim()).getTime(); + dateStr.push(convertedDate); }); updateObj[key].value = dateStr; } } else { - updateObj[key].value = new Date(updateObj[key].value).getTime() + var convertedDate = Globals.needToValidateDate ? Utils.convertToValidDate(updateObj[key].value) : updateObj[key].value; + updateObj[key].value = new Date(convertedDate).getTime(); } } that.model.set(updateObj); diff --git a/dashboardv2/public/js/views/tag/AddTagModalView.js b/dashboardv2/public/js/views/tag/AddTagModalView.js index 1b46291fe..10591e2df 100644 --- a/dashboardv2/public/js/views/tag/AddTagModalView.js +++ b/dashboardv2/public/js/views/tag/AddTagModalView.js @@ -164,7 +164,8 @@ define(['require', $valueElement = $(item); $valueElement.removeClass('errorValidate'); if (datatypeSelection === "date") { - tagAttributes[selection] = Date.parse($valueElement.val()) || null; + var convertedDate = Globals.needToValidateDate ? Utils.convertToValidDate($valueElement.val()) : $valueElement.val(); + tagAttributes[selection] = Date.parse(convertedDate) || null; } else { if (isRequired) { if ($valueElement.val().length) { diff --git a/dashboardv2/public/js/views/tag/AddTimezoneItemView.js b/dashboardv2/public/js/views/tag/AddTimezoneItemView.js index c07eecfe6..3010c1994 100644 --- a/dashboardv2/public/js/views/tag/AddTimezoneItemView.js +++ b/dashboardv2/public/js/views/tag/AddTimezoneItemView.js @@ -136,7 +136,8 @@ define(['require', if (Globals.dateTimeFormat.indexOf("HH") > -1) { option = option.slice(0, -3); // remove AM/PM from 24hr format } - return moment(Date.parse(option)).format('YYYY/MM/DD HH:mm:ss'); + var convertedDate = Globals.needToValidateDate ? Utils.convertToValidDate(option) : option; + return moment(Date.parse(convertedDate)).format('YYYY/MM/DD HH:mm:ss'); } return ""; }, diff --git a/dashboardv3/public/js/main.js b/dashboardv3/public/js/main.js index 31a52ee19..7423c88c3 100644 --- a/dashboardv3/public/js/main.js +++ b/dashboardv3/public/js/main.js @@ -313,6 +313,7 @@ require(['App', } if (response['atlas.ui.date.format'] !== undefined) { Globals.dateTimeFormat = response['atlas.ui.date.format']; + if (Globals.dateTimeFormat.toLocaleLowerCase().indexOf("dd") == 0) Globals.needToValidateDate = true; var dateFormatSeperated = Globals.dateTimeFormat.split(' '); if (dateFormatSeperated[0]) { Globals.dateFormat = dateFormatSeperated[0]; //date @@ -328,10 +329,10 @@ require(['App', Globals.isTasksEnabled = response['atlas.tasks.enabled']; } if (response['atlas.session.timeout.secs']) { Globals.idealTimeoutSeconds = response['atlas.session.timeout.secs']; } - if(response['atlas.lineage.on.demand.enabled'] !== undefined){ + if (response['atlas.lineage.on.demand.enabled'] !== undefined) { Globals.isLineageOnDemandEnabled = response['atlas.lineage.on.demand.enabled']; } - if(response['atlas.lineage.on.demand.default.node.count'] !== undefined){ + if (response['atlas.lineage.on.demand.default.node.count'] !== undefined) { Globals.lineageNodeCount = response['atlas.lineage.on.demand.default.node.count']; } /* Atlas idealTimeout @@ -420,7 +421,7 @@ require(['App', } }); this.relationshipDefCollection.fetch({ - async:true, + async: true, complete: function() { that.relationshipDefCollection.fullCollection.comparator = function(model) { return model.get('name').toLowerCase(); diff --git a/dashboardv3/public/js/utils/CommonViewFunction.js b/dashboardv3/public/js/utils/CommonViewFunction.js index a66937ff0..aa1821742 100644 --- a/dashboardv3/public/js/utils/CommonViewFunction.js +++ b/dashboardv3/public/js/utils/CommonViewFunction.js @@ -654,14 +654,14 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum url = [(obj.id || obj.attributeName), mapApiOperatorToUI(obj.operator), value]; if (obj.operator === "TIME_RANGE") { if (value.indexOf("-") > -1) { - url[2] = value.split('-').map(function(udKey) { - return Date.parse(udKey.trim()).toString() + url[2] = value.split(' - ').map(function(udKey) { + return Globals.needToValidateDate ? Date.parse(Utils.convertToValidDate(udKey.trim())).toString() : Date.parse(udKey.trim()).toString(); }).join(",") } else { url[2] = Enums.queryBuilderDateRangeUIValueToAPI[_.trim(value)] || value; } } else if (value && value.length && type === 'date' && formatedDateToLong) { - url[2] = Date.parse(value); + url[2] = Globals.needToValidateDate ? Date.parse(Utils.convertToValidDate(value)) : Date.parse(value); } if (type) { url.push(type); diff --git a/dashboardv3/public/js/utils/Globals.js b/dashboardv3/public/js/utils/Globals.js index 6b4dafb78..410d82881 100644 --- a/dashboardv3/public/js/utils/Globals.js +++ b/dashboardv3/public/js/utils/Globals.js @@ -49,6 +49,7 @@ define(["require", "underscore"], function(require, _) { // Date Format Globals.dateTimeFormat = "MM/DD/YYYY hh:mm:ss A"; Globals.dateFormat = "MM/DD/YYYY"; + Globals.needToValidateDate = false; Globals.isTimezoneFormatEnabled = true; Globals.isDebugMetricsEnabled = false; diff --git a/dashboardv3/public/js/utils/Utils.js b/dashboardv3/public/js/utils/Utils.js index 1de81f18d..f60d4be5b 100644 --- a/dashboardv3/public/js/utils/Utils.js +++ b/dashboardv3/public/js/utils/Utils.js @@ -957,6 +957,16 @@ define(['require', 'utils/Globals', 'pnotify', 'utils/Messages', 'utils/Enums', $(this).removeClass('button-loader').removeAttr("disabled"); $(this).siblings("button.cancel").prop("disabled", false); } + Utils.convertToValidDate = function(dateValue) { + var value = dateValue.split(" "), + dateSplit = (value[0].indexOf("-") == -1) ? value[0].split("/") : value[0].split("-"); + if (value.length > 1) { + var time = value[1].split(":"); + return new Date(dateSplit[2], (new Number(dateSplit[1]) - 1), dateSplit[0], time[0], time[1], time[2]); + } else { + return new Date(dateSplit[2], (new Number(dateSplit[1]) - 1), dateSplit[0]); + } + } Utils.formatDate = function(options) { var dateValue = null, dateFormat = Globals.dateTimeFormat, diff --git a/dashboardv3/public/js/views/entity/EntityBusinessMetaDataItemView.js b/dashboardv3/public/js/views/entity/EntityBusinessMetaDataItemView.js index e695c4559..a98132ad3 100644 --- a/dashboardv3/public/js/views/entity/EntityBusinessMetaDataItemView.js +++ b/dashboardv3/public/js/views/entity/EntityBusinessMetaDataItemView.js @@ -148,12 +148,14 @@ define(['require', dateStr = []; if (dateValues.length) { _.each(dateValues, function(selectedDate) { - dateStr.push(new Date(selectedDate.trim()).getTime()); + var convertedDate = Globals.needToValidateDate ? Utils.convertToValidDate(selectedDate.trim()).getTime() : new Date(selectedDate.trim()).getTime(); + dateStr.push(convertedDate); }); updateObj[key].value = dateStr; } } else { - updateObj[key].value = new Date(updateObj[key].value).getTime() + var convertedDate = Globals.needToValidateDate ? Utils.convertToValidDate(updateObj[key].value) : updateObj[key].value; + updateObj[key].value = new Date(convertedDate).getTime(); } } that.model.set(updateObj); diff --git a/dashboardv3/public/js/views/tag/AddTagModalView.js b/dashboardv3/public/js/views/tag/AddTagModalView.js index 1b46291fe..7aae2aa17 100644 --- a/dashboardv3/public/js/views/tag/AddTagModalView.js +++ b/dashboardv3/public/js/views/tag/AddTagModalView.js @@ -164,8 +164,9 @@ define(['require', $valueElement = $(item); $valueElement.removeClass('errorValidate'); if (datatypeSelection === "date") { - tagAttributes[selection] = Date.parse($valueElement.val()) || null; - } else { + var convertedDate = Globals.needToValidateDate ? Utils.convertToValidDate($valueElement.val()) : $valueElement.val(); + tagAttributes[selection] = Date.parse(convertedDate) || null; + } else { if (isRequired) { if ($valueElement.val().length) { tagAttributes[selection] = $(item).val() || null; diff --git a/dashboardv3/public/js/views/tag/AddTimezoneItemView.js b/dashboardv3/public/js/views/tag/AddTimezoneItemView.js index c07eecfe6..3010c1994 100644 --- a/dashboardv3/public/js/views/tag/AddTimezoneItemView.js +++ b/dashboardv3/public/js/views/tag/AddTimezoneItemView.js @@ -136,7 +136,8 @@ define(['require', if (Globals.dateTimeFormat.indexOf("HH") > -1) { option = option.slice(0, -3); // remove AM/PM from 24hr format } - return moment(Date.parse(option)).format('YYYY/MM/DD HH:mm:ss'); + var convertedDate = Globals.needToValidateDate ? Utils.convertToValidDate(option) : option; + return moment(Date.parse(convertedDate)).format('YYYY/MM/DD HH:mm:ss'); } return ""; },