From 3de5948979f96cbce48f9dd7b7d5027851320b34 Mon Sep 17 00:00:00 2001
From: Hermann <blumh@ethz.ch>
Date: Sat, 9 Jun 2018 12:33:24 +0200
Subject: [PATCH] fix time conversion when loading existing data into edit mode
 of events

---
 src/views/elements.js | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/views/elements.js b/src/views/elements.js
index 47aa0f3..d8e09fd 100644
--- a/src/views/elements.js
+++ b/src/views/elements.js
@@ -110,9 +110,22 @@ export class datetimeInput {
   view({ attrs: { label, value } }) {
     // set display-settings accoridng to error-state
     const errors = this.getErrors();
-    const initialValue = value || 'T';
-    const initialDate = initialValue.split('T')[0];
-    const initialTime = initialValue.split('T')[1].substring(0, 5);
+    let initialDate;
+    let initialTime;
+    if (value) {
+      const parsed = new Date(value);
+      // convert to locale timezone
+      const locale = {
+        year: parsed.getFullYear(),
+        month: `${parsed.getMonth()}`.padStart(2, '0'),
+        day: `${parsed.getDay()}`.padStart(2, '0'),
+        hour: `${parsed.getHours()}`.padStart(2, '0'),
+        minute: `${parsed.getMinutes()}`.padStart(2, '0'),
+      };
+      initialDate = `${locale.year}-${locale.month}-${locale.day}`;
+      initialTime = `${locale.hour}:${locale.minute}`;
+    }
+    console.log({initialDate, initialTime});
 
     const date = {
       type: 'date',
-- 
GitLab