From 97396e6b60f8b7a54b05c4ad354ec93f8b90f729 Mon Sep 17 00:00:00 2001
From: Jules Laplace <jules@okfoc.us>
Date: Tue, 21 Mar 2017 10:38:48 +0100
Subject: fix date string conversion issue

---
 client/components/MealList.jsx | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

(limited to 'client/components/MealList.jsx')

diff --git a/client/components/MealList.jsx b/client/components/MealList.jsx
index 76cdd25..8f5e5df 100644
--- a/client/components/MealList.jsx
+++ b/client/components/MealList.jsx
@@ -146,7 +146,7 @@ class MealForm extends React.Component {
       userid: props.user.id,
       name: '',
       calories: '',
-      date: new Date (),
+      date: new Date ().toISOString(),
     }
     this.updateState = this.updateState.bind(this)
     this.handleSubmit = this.handleSubmit.bind(this)
@@ -156,7 +156,7 @@ class MealForm extends React.Component {
       id: '',
       name: '',
       calories: '',
-      date: new Date (),
+      date: new Date ().toISOString(),
     })
   }
   pick(meal){
@@ -165,10 +165,11 @@ class MealForm extends React.Component {
   updateState(event){
     const name = event.target.name
     let value = event.target.value
+    console.log(name, value)
     if (name === 'date') {
-      value = new Date(value + 'T' + this.state.date.split("T")[1] ).toString()
+      value = new Date(value + 'T' + this.state.date.split("T")[1] ).toISOString()
     } else if (name === 'time') {
-      value = new Date(this.state.date.split("T")[0] + value).toString()
+      value = new Date(this.state.date.split("T")[0] + value).toISOString()
     } else if (name === 'calories') {
       value = parseInt(value)
     }
@@ -224,9 +225,11 @@ class MealForm extends React.Component {
     if (! canEdit) {
       return (<div></div>)
     }
+    console.log(this.state.date)
 
     const date = parseDate(this.state.date)
     const time = parseTime(this.state.date)
+
     return (
       <form onSubmit={this.handleSubmit} className={action}>
         <input type='hidden' name='id' value={this.state.id} readOnly />
-- 
cgit v1.2.3-70-g09d2

