From ff01c4ece9b1f59a32eb2aa08d47f5759571611d Mon Sep 17 00:00:00 2001
From: FALKE JANOS <janos.falke@etu.unistra.fr>
Date: Fri, 17 Dec 2021 09:17:39 +0100
Subject: [PATCH] Ordre croissant des dates + format des dates de transactions

---
 frontend/src/actions/Bank.actions.js      |  2 +-
 frontend/src/containers/Bank.container.js | 28 ++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/frontend/src/actions/Bank.actions.js b/frontend/src/actions/Bank.actions.js
index 260aa7f..56bbe1e 100644
--- a/frontend/src/actions/Bank.actions.js
+++ b/frontend/src/actions/Bank.actions.js
@@ -40,7 +40,7 @@ export const fetchUserTransactions = (student_number) => {
             response.json().then(data => {
                 console.log(data);
                 let balance = data.rows.map(data => data.amount).reduce((sum, amount) => sum + amount);
-                let data_sorted = data.rows.sort(function(a,b){return Date.parse(a.concluded_at) - Date.parse(b.concluded_at)});
+                let data_sorted = data.rows.sort(function(a,b){return  Date.parse(b.concluded_at) - Date.parse(a.concluded_at)});
                 dispatch(transactionDataFetchSuccess({balance: balance, transactions: data_sorted}));
             }).catch(err => dispatch(transactionDataFetchFailure(err)));
         }
diff --git a/frontend/src/containers/Bank.container.js b/frontend/src/containers/Bank.container.js
index eac5ad2..751bb01 100644
--- a/frontend/src/containers/Bank.container.js
+++ b/frontend/src/containers/Bank.container.js
@@ -28,6 +28,32 @@ export class Bank extends React.Component {
     console.log('MOUNT PROPS', this.props);
   }
 
+  convertDate(formated_Date){
+    const date = new Date(formated_Date);
+
+    let day = parseInt(date.getDate());
+    if(day < 10){
+      day = "0" + day;
+    }
+
+    let month = parseInt(date.getMonth() + 1);
+    if(month < 10){
+      month = "0" + month;
+    }
+
+    let hours = parseInt(date.getHours());
+    if(hours < 10){
+      hours = "0" + hours;
+    }
+
+    let minutes = parseInt(date.getMinutes());
+    if(minutes < 10){
+      minutes = "0" + minutes;
+    }
+
+    return day + "/" + month + "/" + date.getFullYear() + " " + hours + ":" + minutes;
+  }
+
   render() {
   	return (
       <div>
@@ -54,7 +80,7 @@ export class Bank extends React.Component {
                     return (
                       <tr key={'trans'+transaction.id}>
                         <td><Image src={logo_trans} alt='transaction' width={30} height={30} /></td>
-                        <td style={{fontStyle:'italic'}} colSpan='3'>{transaction.concluded_at}</td>
+                        <td style={{fontStyle:'italic'}} colSpan='3'>{this.convertDate(transaction.concluded_at)}</td>
                         <td style={{fontStyle:'italic', color:'#242424'}} colSpan='3'>{transaction.comment}</td>
                         <td>{transaction.amount}€</td>
                       </tr>
-- 
GitLab