From bb189decae2f1afd3dd07c8fa7f4e795c40ef351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Fri, 26 Nov 2021 01:37:25 +0000 Subject: [PATCH 1/2] fix: date parsing and formatting --- .../src/pages/Accounting/Accounting.js | 4 ++-- .../src/pages/Customers/CustomerData.js | 21 +++++++++++++++---- .../pages/Customers/components/IdDataCard.js | 21 ++++++++++++------- .../Customers/components/TransactionsList.js | 7 +++---- new-lamassu-admin/src/pages/MachineLogs.js | 2 +- .../src/pages/Maintenance/CashboxHistory.js | 2 +- .../pages/Maintenance/MachineDetailsCard.js | 2 +- 7 files changed, 38 insertions(+), 21 deletions(-) diff --git a/new-lamassu-admin/src/pages/Accounting/Accounting.js b/new-lamassu-admin/src/pages/Accounting/Accounting.js index 7f7b7f07..74d65a88 100644 --- a/new-lamassu-admin/src/pages/Accounting/Accounting.js +++ b/new-lamassu-admin/src/pages/Accounting/Accounting.js @@ -158,14 +158,14 @@ const Accounting = () => { width: 150, size: 'sm', textAlign: 'right', - view: it => formatDate(it.created, timezone, 'YYYY-MM-DD') + view: it => formatDate(it.created, timezone, 'yyyy-MM-dd') }, { header: 'Time', width: 150, size: 'sm', textAlign: 'right', - view: it => formatDate(it.created, timezone, 'YYYY-MM-DD') + view: it => formatDate(it.created, timezone, 'yyyy-MM-dd') } ] diff --git a/new-lamassu-admin/src/pages/Customers/CustomerData.js b/new-lamassu-admin/src/pages/Customers/CustomerData.js index e957211c..bb034bbd 100644 --- a/new-lamassu-admin/src/pages/Customers/CustomerData.js +++ b/new-lamassu-admin/src/pages/Customers/CustomerData.js @@ -1,6 +1,6 @@ import Grid from '@material-ui/core/Grid' import { makeStyles } from '@material-ui/core/styles' -import { differenceInYears, format } from 'date-fns/fp' +import { differenceInYears, parse, format } from 'date-fns/fp' import _ from 'lodash/fp' import * as R from 'ramda' import { useState, React } from 'react' @@ -115,13 +115,22 @@ const CustomerData = ({ customer, updateCustomer }) => { { name: 'birthDate', label: 'Birth Date', - value: (rawDob && format('yyyy-MM-dd', rawDob)) ?? '', + value: + (rawDob && + format('yyyy-MM-dd')(parse(new Date(), 'yyyyMMdd', rawDob))) ?? + '', component: TextInput }, { name: 'age', label: 'Age', - value: (rawDob && differenceInYears(rawDob, new Date())) ?? '', + value: + (rawDob && + differenceInYears( + parse(new Date(), 'yyyyMMdd', rawDob), + new Date() + )) ?? + '', component: TextInput }, { @@ -140,7 +149,11 @@ const CustomerData = ({ customer, updateCustomer }) => { name: 'expirationDate', label: 'Expiration Date', value: - (rawExpirationDate && format('yyyy-MM-dd', rawExpirationDate)) ?? '', + (rawExpirationDate && + format('yyyy-MM-dd')( + parse(new Date(), 'yyyyMMdd', rawExpirationDate) + )) ?? + '', component: TextInput } ] diff --git a/new-lamassu-admin/src/pages/Customers/components/IdDataCard.js b/new-lamassu-admin/src/pages/Customers/components/IdDataCard.js index 5da592ff..3083283f 100644 --- a/new-lamassu-admin/src/pages/Customers/components/IdDataCard.js +++ b/new-lamassu-admin/src/pages/Customers/components/IdDataCard.js @@ -1,5 +1,5 @@ import { Box } from '@material-ui/core' -import { differenceInYears, format } from 'date-fns/fp' +import { differenceInYears, format, parse } from 'date-fns/fp' import * as R from 'ramda' import React, { memo } from 'react' @@ -9,7 +9,6 @@ import { OVERRIDE_REJECTED } from 'src/pages/Customers/components/propertyCard' import { ifNotNull } from 'src/utils/nullCheck' -import { toUtc } from 'src/utils/timezones' import { getName } from '../helper' @@ -34,15 +33,21 @@ const IdDataCard = memo(({ customerData, updateCustomer }) => { }, { header: 'Birth Date', - display: ifNotNull(rawDob, format('YYYY-MM-DD', rawDob)), + display: + (rawDob && + format('yyyy-MM-dd')(parse(new Date(), 'yyyyMMdd', rawDob))) ?? + '', size: 110 }, { header: 'Age', - display: ifNotNull( - rawDob, - differenceInYears(toUtc(rawDob), toUtc(new Date())) - ), + display: + (rawDob && + differenceInYears( + parse(new Date(), 'yyyyMMdd', rawDob), + new Date() + )) ?? + '', size: 50 }, { @@ -59,7 +64,7 @@ const IdDataCard = memo(({ customerData, updateCustomer }) => { header: 'Expiration Date', display: ifNotNull( rawExpirationDate, - format('YYYY-MM-DD', rawExpirationDate) + format('yyyy-MM-dd', rawExpirationDate) ) } ] diff --git a/new-lamassu-admin/src/pages/Customers/components/TransactionsList.js b/new-lamassu-admin/src/pages/Customers/components/TransactionsList.js index 5b150b51..a3c16f06 100644 --- a/new-lamassu-admin/src/pages/Customers/components/TransactionsList.js +++ b/new-lamassu-admin/src/pages/Customers/components/TransactionsList.js @@ -50,10 +50,9 @@ const TransactionsList = ({ customer, data, loading, locale }) => { size: 142, value: !R.isNil(timezone) && - ifNotNull( - customer.lastActive, - formatDate(customer.lastActive, timezone, 'yyyy-MM-d') - ) + ((customer.lastActive && + formatDate(customer.lastActive, timezone, 'yyyy-MM-d')) ?? + '') }, { header: 'Last transaction', diff --git a/new-lamassu-admin/src/pages/MachineLogs.js b/new-lamassu-admin/src/pages/MachineLogs.js index 3075eb80..277b82c5 100644 --- a/new-lamassu-admin/src/pages/MachineLogs.js +++ b/new-lamassu-admin/src/pages/MachineLogs.js @@ -142,7 +142,7 @@ const Logs = () => { {timezone && - formatDate(log.timestamp, timezone, 'YYYY-MM-DD HH:mm')} + formatDate(log.timestamp, timezone, 'yyyy-MM-dd HH:mm')} {log.logLevel} {log.message} diff --git a/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js b/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js index be484692..3e13740b 100644 --- a/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js +++ b/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js @@ -187,7 +187,7 @@ const CashboxHistory = ({ machines, currency }) => { header: 'Date', width: 135, textAlign: 'right', - view: it => formatDate(it.created, timezone, 'YYYY-MM-DD') + view: it => formatDate(it.created, timezone, 'yyyy-MM-dd') }, { name: 'time', diff --git a/new-lamassu-admin/src/pages/Maintenance/MachineDetailsCard.js b/new-lamassu-admin/src/pages/Maintenance/MachineDetailsCard.js index a81e6a5f..0aaf1ea2 100644 --- a/new-lamassu-admin/src/pages/Maintenance/MachineDetailsCard.js +++ b/new-lamassu-admin/src/pages/Maintenance/MachineDetailsCard.js @@ -99,7 +99,7 @@ const MachineDetailsRow = ({ it: machine, onActionSuccess, timezone }) => { {timezone && - formatDate(machine.pairedAt, timezone, 'YYYY-MM-DD HH:mm:ss')} + formatDate(machine.pairedAt, timezone, 'yyyy-MM-dd HH:mm:ss')} From 88ed1871764612dffa02ed1e828ff15a53583675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Fri, 26 Nov 2021 16:13:04 +0000 Subject: [PATCH 2/2] fix: change date instances of single-digit days to double-digit --- new-lamassu-admin/src/pages/Customers/CustomersList.js | 2 +- .../src/pages/Customers/components/TransactionsList.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/new-lamassu-admin/src/pages/Customers/CustomersList.js b/new-lamassu-admin/src/pages/Customers/CustomersList.js index 2fdaadc9..43e40c2a 100644 --- a/new-lamassu-admin/src/pages/Customers/CustomersList.js +++ b/new-lamassu-admin/src/pages/Customers/CustomersList.js @@ -44,7 +44,7 @@ const CustomersList = ({ data, locale, onClick, loading }) => { header: 'Last active', width: 137, view: it => - (it.lastActive && format('yyyy-MM-d', new Date(it.lastActive))) ?? '' + (it.lastActive && format('yyyy-MM-dd', new Date(it.lastActive))) ?? '' }, { header: 'Last transaction', diff --git a/new-lamassu-admin/src/pages/Customers/components/TransactionsList.js b/new-lamassu-admin/src/pages/Customers/components/TransactionsList.js index a3c16f06..9bbd35de 100644 --- a/new-lamassu-admin/src/pages/Customers/components/TransactionsList.js +++ b/new-lamassu-admin/src/pages/Customers/components/TransactionsList.js @@ -51,7 +51,7 @@ const TransactionsList = ({ customer, data, loading, locale }) => { value: !R.isNil(timezone) && ((customer.lastActive && - formatDate(customer.lastActive, timezone, 'yyyy-MM-d')) ?? + formatDate(customer.lastActive, timezone, 'yyyy-MM-dd')) ?? '') }, { @@ -121,7 +121,7 @@ const TransactionsList = ({ customer, data, loading, locale }) => { { header: 'Date', width: 100, - view: it => formatDate(it.created, timezone, 'yyyy-MM-d') + view: it => formatDate(it.created, timezone, 'yyyy-MM-dd') }, { header: 'Time (h:m:s)',