fix: date parsing and formatting

This commit is contained in:
Sérgio Salgado 2021-11-26 01:37:25 +00:00
parent 1cb715332a
commit bb189decae
7 changed files with 38 additions and 21 deletions

View file

@ -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')
}
]

View file

@ -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
}
]

View file

@ -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)
)
}
]

View file

@ -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',

View file

@ -142,7 +142,7 @@ const Logs = () => {
<TableRow key={idx} size="sm">
<TableCell>
{timezone &&
formatDate(log.timestamp, timezone, 'YYYY-MM-DD HH:mm')}
formatDate(log.timestamp, timezone, 'yyyy-MM-dd HH:mm')}
</TableCell>
<TableCell>{log.logLevel}</TableCell>
<TableCell>{log.message}</TableCell>

View file

@ -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',

View file

@ -99,7 +99,7 @@ const MachineDetailsRow = ({ it: machine, onActionSuccess, timezone }) => {
<Label>Paired at</Label>
<span>
{timezone &&
formatDate(machine.pairedAt, timezone, 'YYYY-MM-DD HH:mm:ss')}
formatDate(machine.pairedAt, timezone, 'yyyy-MM-dd HH:mm:ss')}
</span>
</Item>
<Item xs={6}>