rewrite using isToday helper

This commit is contained in:
Artem Baskal 2020-01-17 17:40:47 +03:00
parent a3020275a2
commit af7b9523b5
2 changed files with 6 additions and 17 deletions

View File

@ -9,7 +9,7 @@ import { HashLink as Link } from 'react-router-hash-link';
import { import {
formatTime, formatTime,
formatDateTime, formatDateTime,
formatTodayDate, isToday,
} from '../../helpers/helpers'; } from '../../helpers/helpers';
import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE } from '../../helpers/constants'; import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE } from '../../helpers/constants';
import { getTrackerData } from '../../helpers/trackers/trackers'; import { getTrackerData } from '../../helpers/trackers/trackers';
@ -118,8 +118,7 @@ class Logs extends Component {
getTimeCell = ({ value }) => ( getTimeCell = ({ value }) => (
<div className="logs__row"> <div className="logs__row">
<span className="logs__text" title={formatDateTime(value)}> <span className="logs__text" title={formatDateTime(value)}>
{formatTodayDate(value) === formatTodayDate(Date.now()) {isToday(value) ? formatTime(value) : formatDateTime(value)}
? formatTime(value) : formatDateTime(value)}
</span> </span>
</div> </div>
); );

View File

@ -5,6 +5,7 @@ import subHours from 'date-fns/sub_hours';
import addHours from 'date-fns/add_hours'; import addHours from 'date-fns/add_hours';
import addDays from 'date-fns/add_days'; import addDays from 'date-fns/add_days';
import subDays from 'date-fns/sub_days'; import subDays from 'date-fns/sub_days';
import isSameDay from 'date-fns/is_same_day';
import round from 'lodash/round'; import round from 'lodash/round';
import axios from 'axios'; import axios from 'axios';
import i18n from 'i18next'; import i18n from 'i18next';
@ -48,21 +49,10 @@ export const formatDateTime = (dateTime) => {
}; };
/** /**
* @param string The date to format * @param string
* @returns string Returns the date in the format DD/MM/YYYY * @returns boolean
*/ */
export const formatTodayDate = (dateTime) => { export const isToday = date => isSameDay(new Date(date), new Date());
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 normalizeLogs = logs => logs.map((log) => { export const normalizeLogs = logs => logs.map((log) => {
const { const {