diff --git a/client/src/components/Logs/index.js b/client/src/components/Logs/index.js index 449a6538..1569075e 100644 --- a/client/src/components/Logs/index.js +++ b/client/src/components/Logs/index.js @@ -9,6 +9,7 @@ import { HashLink as Link } from 'react-router-hash-link'; import { formatTime, formatDateTime, + isToday, } from '../../helpers/helpers'; import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE } from '../../helpers/constants'; import { getTrackerData } from '../../helpers/trackers/trackers'; @@ -116,9 +117,9 @@ class Logs extends Component { getTimeCell = ({ value }) => (
- - {formatTime(value)} - + + {isToday(value) ? formatTime(value) : formatDateTime(value)} +
); @@ -257,7 +258,7 @@ class Logs extends Component { { Header: t('time_table_header'), accessor: 'time', - maxWidth: 100, + minWidth: 105, Cell: this.getTimeCell, }, { diff --git a/client/src/helpers/helpers.js b/client/src/helpers/helpers.js index d4deef2a..62fe3b66 100644 --- a/client/src/helpers/helpers.js +++ b/client/src/helpers/helpers.js @@ -5,6 +5,7 @@ import subHours from 'date-fns/sub_hours'; import addHours from 'date-fns/add_hours'; import addDays from 'date-fns/add_days'; import subDays from 'date-fns/sub_days'; +import isSameDay from 'date-fns/is_same_day'; import round from 'lodash/round'; import axios from 'axios'; import i18n from 'i18next'; @@ -19,11 +20,19 @@ import { DNS_RECORD_TYPES, } from './constants'; +/** + * @param string The time to format + * @returns string Returns the time in the format HH:mm:ss + */ export const formatTime = (time) => { const parsedTime = dateParse(time); return dateFormat(parsedTime, 'HH:mm:ss'); }; +/** + * @param string The date to format + * @returns string Returns the date and time in the format DD/MM/YYYY, HH:mm + */ export const formatDateTime = (dateTime) => { const currentLanguage = i18n.languages[0] || 'en'; const parsedTime = dateParse(dateTime); @@ -39,6 +48,12 @@ export const formatDateTime = (dateTime) => { return parsedTime.toLocaleString(currentLanguage, options); }; +/** + * @param string + * @returns boolean + */ +export const isToday = date => isSameDay(new Date(date), new Date()); + export const normalizeLogs = logs => logs.map((log) => { const { time,