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 [anchorEl, setAnchorEl] = useState(null)
const [fetchLogs] = useLazyQuery(query, {
onCompleted: data => createLogsFile(getLogs(data), range)
onCompleted: data => {
console.log(data)
return createLogsFile(getLogs(data), range)
}
})
const classes = useStyles()

View file

@ -47,7 +47,7 @@ const TransactionsList = ({ customer, data, loading, locale }) => {
!R.isNil(timezone) &&
ifNotNull(
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',
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)',
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">
<TableCell>
{timezone &&
formatDate(
log.timestamp,
timezone.dstOffset,
'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

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

View file

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

View file

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

View file

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

View file

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