From b5c161b4b098e5f303cb81cd782c5abe88722456 Mon Sep 17 00:00:00 2001
From: Sukanya Pandey <sukapan1@in.ibm.com>
Date: Thu, 30 Jul 2020 21:56:03 +0530
Subject: Remove time bug from date and time settings page

 -Bug is while setting the UTC time, UTC time is getting saved
 with offset as per the timezone.
 -After this commit the UTC time will be saved as UTC time with no offset.

Signed-off-by: Sukanya Pandey <sukapan1@in.ibm.com>
Change-Id: I4731cb1f8e3daae3801059e1653d059c51c26f7d
---
 .../DateTimeSettings/DateTimeSettings.vue          | 30 +++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

(limited to 'src/views/Configuration/DateTimeSettings/DateTimeSettings.vue')

diff --git a/src/views/Configuration/DateTimeSettings/DateTimeSettings.vue b/src/views/Configuration/DateTimeSettings/DateTimeSettings.vue
index 2e3fc195..f1b64751 100644
--- a/src/views/Configuration/DateTimeSettings/DateTimeSettings.vue
+++ b/src/views/Configuration/DateTimeSettings/DateTimeSettings.vue
@@ -317,10 +317,20 @@ export default {
       let isNTPEnabled = this.form.configurationSelected === 'ntp';
 
       if (!isNTPEnabled) {
+        const isUtcDisplay = this.$store.getters['global/isUtcDisplay'];
+        let date;
+
         dateTimeForm.ntpProtocolEnabled = false;
-        dateTimeForm.updatedDateTime = new Date(
-          `${this.form.manual.date} ${this.form.manual.time}`
-        ).toISOString();
+
+        if (isUtcDisplay) {
+          // Create UTC Date
+          date = this.getUtcDate(this.form.manual.date, this.form.manual.time);
+        } else {
+          // Create local Date
+          date = new Date(`${this.form.manual.date} ${this.form.manual.time}`);
+        }
+
+        dateTimeForm.updatedDateTime = date.toISOString();
       } else {
         ntpFirstAddress = this.form.ntp.firstAddress;
         ntpSecondAddress = this.form.ntp.secondAddress;
@@ -353,6 +363,20 @@ export default {
           this.$v.form.$reset();
           this.endLoader();
         });
+    },
+    getUtcDate(date, time) {
+      // Split user input string values to create
+      // a UTC Date object
+      const datesArray = date.split('-');
+      const timeArray = time.split(':');
+      let utcDate = Date.UTC(
+        datesArray[0], // User input year
+        datesArray[1], // User input month
+        datesArray[2], // User input day
+        timeArray[0], // User input hour
+        timeArray[1] // User input minute
+      );
+      return new Date(utcDate);
     }
   }
 };
-- 
cgit v1.2.3

