Dates are now handled as UNIX dates

This commit is contained in:
bourquecharles
2021-05-26 17:03:50 -04:00
parent 18a8794891
commit 8bc3cd3a0d
5 changed files with 20 additions and 14 deletions

View File

@@ -17,7 +17,7 @@ import { cilSync } from '@coreui/icons';
import PropTypes from 'prop-types';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faClipboardCheck } from '@fortawesome/free-solid-svg-icons'
import { prettyDate, addDays } from '../../utils/helper';
import { prettyDate, addDays, dateToUnix } from '../../utils/helper';
import axiosInstance from '../../utils/axiosInstance';
import { getToken } from '../../utils/authHelper';
import WifiScanResultModalWidget from './WifiScanResultModal';
@@ -78,8 +78,8 @@ const DeviceCommands = ({ selectedDeviceId }) => {
Authorization: `Bearer ${getToken()}`,
},
params: {
startDate: utcStart,
endDate: utcEnd,
startDate: dateToUnix(utcStart),
endDate: dateToUnix(utcEnd),
},
};

View File

@@ -14,7 +14,7 @@ import {
} from '@coreui/react';
import CIcon from '@coreui/icons-react';
import PropTypes from 'prop-types';
import { cleanTimestamp } from '../../utils/helper';
import { prettyDate } from '../../utils/helper';
import axiosInstance from '../../utils/axiosInstance';
import { getToken } from '../../utils/authHelper';
@@ -82,7 +82,7 @@ const DeviceConfiguration = ({ selectedDeviceId }) => {
<CLabel>Last Configuration Change : </CLabel>
</CCol>
<CCol xs="12" md="9">
{cleanTimestamp(device.lastConfigurationChange)}
{prettyDate(device.lastConfigurationChange)}
</CCol>
</CFormGroup>
<CFormGroup row>
@@ -98,7 +98,7 @@ const DeviceConfiguration = ({ selectedDeviceId }) => {
<CLabel>Created : </CLabel>
</CCol>
<CCol xs="12" md="9">
{cleanTimestamp(device.createdTimestamp)}
{prettyDate(device.createdTimestamp)}
</CCol>
</CFormGroup>
<CFormGroup row>
@@ -106,7 +106,7 @@ const DeviceConfiguration = ({ selectedDeviceId }) => {
<CLabel>Last Configuration Download : </CLabel>
</CCol>
<CCol xs="12" md="9">
{cleanTimestamp(device.lastConfigurationDownload)}
{prettyDate(device.lastConfigurationDownload)}
</CCol>
</CFormGroup>
<CCollapse show={collapse}>

View File

@@ -14,7 +14,7 @@ import {
import CIcon from '@coreui/icons-react';
import DatePicker from 'react-widgets/DatePicker';
import PropTypes from 'prop-types';
import { prettyDate, addDays } from '../../utils/helper';
import { prettyDate, addDays, dateToUnix } from '../../utils/helper';
import axiosInstance from '../../utils/axiosInstance';
import { getToken } from '../../utils/authHelper';
@@ -52,8 +52,8 @@ const DeviceHealth = ({ selectedDeviceId }) => {
Authorization: `Bearer ${getToken()}`,
},
params: {
startDate: utcStart,
endDate: utcEnd,
startDate: dateToUnix(utcStart),
endDate: dateToUnix(utcEnd),
},
};

View File

@@ -13,7 +13,7 @@ import {
import CIcon from '@coreui/icons-react';
import DatePicker from 'react-widgets/DatePicker';
import PropTypes from 'prop-types';
import { addDays, prettyDate } from '../../utils/helper';
import { addDays, prettyDate, dateToUnix } from '../../utils/helper';
import axiosInstance from '../../utils/axiosInstance';
import { getToken } from '../../utils/authHelper';
@@ -49,8 +49,8 @@ const DeviceLogs = ({ selectedDeviceId }) => {
Authorization: `Bearer ${getToken()}`,
},
params: {
startDate: utcStart,
endDate: utcEnd,
startDate: dateToUnix(utcStart),
endDate: dateToUnix(utcEnd),
},
};

View File

@@ -43,10 +43,16 @@ const prettyNumber = (number) => {
return `0${number}`;
};
const unixToDateString = (unixNumber) => unixNumber * 1000;
export const prettyDate = (dateString) => {
const date = new Date(dateString);
const convertedTimestamp = unixToDateString(dateString);
const date = new Date(convertedTimestamp);
return `${date.getFullYear()}-${prettyNumber(date.getMonth() + 1)}-${prettyNumber(date.getDate())}
${prettyNumber(date.getHours())}:${prettyNumber(date.getMinutes())}:${prettyNumber(
date.getSeconds(),
)}`;
};
export const dateToUnix = (date) => new Date(date).getTime()/1000;