From c2c3ab9a1818a3e623e87c6f19b446a724fd1952 Mon Sep 17 00:00:00 2001 From: smit95tpatel Date: Tue, 21 Dec 2021 00:48:23 +0530 Subject: [PATCH] fixed issues on dates --- .../Dashboard/DashboardDowntimes.vue | 46 +++++++-------- frontend/src/forms/Downtime.vue | 56 ++++++++++++++----- frontend/src/forms/DowntimeFilters.vue | 13 ++--- 3 files changed, 70 insertions(+), 45 deletions(-) diff --git a/frontend/src/components/Dashboard/DashboardDowntimes.vue b/frontend/src/components/Dashboard/DashboardDowntimes.vue index 738cd1fc..bbd0df9e 100644 --- a/frontend/src/components/Dashboard/DashboardDowntimes.vue +++ b/frontend/src/components/Dashboard/DashboardDowntimes.vue @@ -67,10 +67,29 @@ export const initialParams = { subStatus: '' }; -const convertToSec = (val) => { +export const convertToSec = (val) => { return +new Date(val)/1000; }; +export const checkErrors = (params) => { + const { start, end } = params; + const errors = {}; + + // Converting into millisec + const startSec = convertToSec(start); + const endSec = convertToSec(end) + (60 * 60 * 23 + 59 * 60 + 59); + + if (!start && end) { + errors.start = 'Need to enter Start Date'; + } else if (start && !end) { + errors.end = 'Need to enter End Date'; + } else if ( startSec > endSec ) { + errors.end = 'End Date should be greater than Start Date'; + } + + return errors; +}; + export default { name: 'DashboardDowntimes', components: { @@ -91,7 +110,7 @@ export default { created: function () { // Set start date const startDate = new Date(); - startDate.setDate(-10); + startDate.setDate(startDate.getDate() - 30); startDate.setHours(0,0,0,0); this.params.start = startDate.toJSON(); @@ -106,9 +125,10 @@ export default { getDowntimes: async function (params = this.params) { const { start, end } = params; - this.checkFilterErrors(); + const errors = checkErrors(this.params); - if (Object.keys(this.filterErrors).length > 0) { + if (Object.keys(errors).length > 0) { + this.filterErrors = Object.assign({}, errors); return; } @@ -142,24 +162,6 @@ export default { this.getDowntimes(); }, - checkFilterErrors: function () { - const { start, end } = this.params; - const errors = {}; - - // Converting into millisec - const startSec = convertToSec(start); - const endSec = convertToSec(end) + (60 * 60 * 23 + 59 * 60 + 59); - - if (!start && end) { - errors.start = 'Need to enter Start Date'; - } else if (start && !end) { - errors.end = 'Need to enter End Date'; - } else if ( startSec > endSec ) { - errors.end = 'End Date should be greater than Start Date'; - } - - this.filterErrors = Object.assign({}, errors); - }, handleFilterChange: function (e) { const { name } = e.target; diff --git a/frontend/src/forms/Downtime.vue b/frontend/src/forms/Downtime.vue index 5a2cdf42..b3b75590 100644 --- a/frontend/src/forms/Downtime.vue +++ b/frontend/src/forms/Downtime.vue @@ -90,6 +90,12 @@ :config="config" placeholder="Select Start Date" /> + + {{ errors.start }} +
+ + {{ errors.end }} +
{{ errors.failures }} @@ -144,7 +157,7 @@