diff --git a/client/src/components/Logs/index.js b/client/src/components/Logs/index.js index ebe058e8..1569075e 100644 --- a/client/src/components/Logs/index.js +++ b/client/src/components/Logs/index.js @@ -9,7 +9,7 @@ import { HashLink as Link } from 'react-router-hash-link'; import { formatTime, formatDateTime, - formatTodayDate, + isToday, } from '../../helpers/helpers'; import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE } from '../../helpers/constants'; import { getTrackerData } from '../../helpers/trackers/trackers'; @@ -118,8 +118,7 @@ class Logs extends Component { getTimeCell = ({ value }) => (
- {formatTodayDate(value) === formatTodayDate(Date.now()) - ? formatTime(value) : formatDateTime(value)} + {isToday(value) ? formatTime(value) : formatDateTime(value)}
); diff --git a/client/src/helpers/helpers.js b/client/src/helpers/helpers.js index bda48e48..cf6db0fe 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'; @@ -48,21 +49,10 @@ export const formatDateTime = (dateTime) => { }; /** - * @param string The date to format - * @returns string Returns the date in the format DD/MM/YYYY + * @param string + * @returns boolean */ -export const formatTodayDate = (dateTime) => { - const currentLanguage = i18n.languages[0] || 'en'; - const parsedTime = dateParse(dateTime); - const options = { - year: 'numeric', - month: 'numeric', - day: 'numeric', - hour12: false, - }; - - return parsedTime.toLocaleString(currentLanguage, options); -}; +export const isToday = date => isSameDay(new Date(date), new Date()); export const normalizeLogs = logs => logs.map((log) => { const {