fix: formatDate working with timezone code

This commit is contained in:
Sérgio Salgado 2021-05-25 08:43:58 +01:00 committed by Josh Harvey
parent 0429563e42
commit 78a4c9f267
8 changed files with 17 additions and 25 deletions

View file

@ -134,7 +134,10 @@ const LogsDownloaderPopover = ({ name, query, args, title, getLogs }) => {
const [range, setRange] = useState({ from: null, until: null }) const [range, setRange] = useState({ from: null, until: null })
const [anchorEl, setAnchorEl] = useState(null) const [anchorEl, setAnchorEl] = useState(null)
const [fetchLogs] = useLazyQuery(query, { const [fetchLogs] = useLazyQuery(query, {
onCompleted: data => createLogsFile(getLogs(data), range) onCompleted: data => {
console.log(data)
return createLogsFile(getLogs(data), range)
}
}) })
const classes = useStyles() const classes = useStyles()

View file

@ -47,7 +47,7 @@ const TransactionsList = ({ customer, data, loading, locale }) => {
!R.isNil(timezone) && !R.isNil(timezone) &&
ifNotNull( ifNotNull(
customer.lastActive, customer.lastActive,
formatDate(customer.lastActive, timezone.dstOffset, 'YYYY-MM-D') formatDate(customer.lastActive, timezone, 'YYYY-MM-D')
) )
}, },
{ {
@ -113,12 +113,12 @@ const TransactionsList = ({ customer, data, loading, locale }) => {
{ {
header: 'Date', header: 'Date',
width: 157, width: 157,
view: it => formatDate(it.created, timezone.dstOffset, 'YYYY-MM-D') view: it => formatDate(it.created, timezone, 'YYYY-MM-D')
}, },
{ {
header: 'Time (h:m:s)', header: 'Time (h:m:s)',
width: 134, width: 134,
view: it => formatDate(it.created, timezone.dstOffset, 'HH:mm:ss') view: it => formatDate(it.created, timezone, 'HH:mm:ss')
} }
] ]

View file

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

View file

@ -15,11 +15,7 @@ const Details = ({ data, timezone }) => {
<Label3 className={classes.label3}>Paired at</Label3> <Label3 className={classes.label3}>Paired at</Label3>
<P> <P>
{data.pairedAt {data.pairedAt
? formatDate( ? formatDate(data.pairedAt, timezone, 'YYYY-MM-DD HH:mm:ss')
data.pairedAt,
timezone.dstOffset,
'YYYY-MM-DD HH:mm:ss'
)
: ''} : ''}
</P> </P>
</div> </div>

View file

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

View file

@ -189,7 +189,7 @@ const Logs = () => {
{timezone && {timezone &&
formatDate( formatDate(
log.timestamp, log.timestamp,
timezone.dstOffset, timezone,
'YYYY-MM-DD HH:mm' 'YYYY-MM-DD HH:mm'
)} )}
</TableCell> </TableCell>

View file

@ -153,8 +153,7 @@ const Transactions = () => {
{ {
header: 'Date (UTC)', header: 'Date (UTC)',
view: it => view: it =>
timezone && timezone && formatDate(it.created, timezone, 'YYYY-MM-DD HH:mm:ss'),
formatDate(it.created, timezone.dstOffset, 'YYYY-MM-DD HH:mm:ss'),
textAlign: 'right', textAlign: 'right',
size: 'sm', size: 'sm',
width: 195 width: 195

View file

@ -74,10 +74,12 @@ const getTzLabels = timezones =>
getFinalTimezones(timezones) getFinalTimezones(timezones)
) )
const formatDate = (date, offset, format) => const formatDate = (date, timezoneCode, format) => {
moment const dstOffset = timezoneCode.split(':')[1]
return moment
.utc(date) .utc(date)
.utcOffset(offset) .utcOffset(parseInt(dstOffset))
.format(format) .format(format)
}
export { getTzLabels, formatDate } export { getTzLabels, formatDate }