From 108cf73a307f248b1dbc9cb943c75a1adf431f0a Mon Sep 17 00:00:00 2001 From: Artem Baskal Date: Tue, 24 Dec 2019 00:29:10 +0300 Subject: [PATCH 1/3] + client: show date in query logs --- client/src/components/Logs/index.js | 14 ++++++++------ client/src/helpers/helpers.js | 13 +++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/client/src/components/Logs/index.js b/client/src/components/Logs/index.js index 449a6538..940769ef 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, + formatTodayDate, } from '../../helpers/helpers'; import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE } from '../../helpers/constants'; import { getTrackerData } from '../../helpers/trackers/trackers'; @@ -115,11 +116,12 @@ class Logs extends Component { checkWhiteList = reason => reason === FILTERED_STATUS.NOT_FILTERED_WHITE_LIST; getTimeCell = ({ value }) => ( -
- - {formatTime(value)} - -
+
+ + {formatTodayDate(value) === formatTodayDate(Date.now()) + ? formatTime(value) : formatDateTime(value)} + +
); getDomainCell = (row) => { @@ -257,7 +259,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 8f9556af..53a821f0 100644 --- a/client/src/helpers/helpers.js +++ b/client/src/helpers/helpers.js @@ -39,6 +39,19 @@ export const formatDateTime = (dateTime) => { return parsedTime.toLocaleString(currentLanguage, options); }; +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 normalizeLogs = logs => logs.map((log) => { const { time, From a3020275a263fced7cd17ebccf917e752ffcd8bb Mon Sep 17 00:00:00 2001 From: Artem Baskal Date: Fri, 17 Jan 2020 12:57:30 +0300 Subject: [PATCH 2/3] + client: add jsdocs with returning format of date format functions --- client/src/components/Logs/index.js | 4 ++-- client/src/helpers/helpers.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/client/src/components/Logs/index.js b/client/src/components/Logs/index.js index 940769ef..ebe058e8 100644 --- a/client/src/components/Logs/index.js +++ b/client/src/components/Logs/index.js @@ -116,12 +116,12 @@ class Logs extends Component { checkWhiteList = reason => reason === FILTERED_STATUS.NOT_FILTERED_WHITE_LIST; getTimeCell = ({ value }) => ( -
+
{formatTodayDate(value) === formatTodayDate(Date.now()) ? formatTime(value) : formatDateTime(value)} -
+
); getDomainCell = (row) => { diff --git a/client/src/helpers/helpers.js b/client/src/helpers/helpers.js index 53a821f0..bda48e48 100644 --- a/client/src/helpers/helpers.js +++ b/client/src/helpers/helpers.js @@ -19,11 +19,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 +47,10 @@ export const formatDateTime = (dateTime) => { return parsedTime.toLocaleString(currentLanguage, options); }; +/** + * @param string The date to format + * @returns string Returns the date in the format DD/MM/YYYY + */ export const formatTodayDate = (dateTime) => { const currentLanguage = i18n.languages[0] || 'en'; const parsedTime = dateParse(dateTime); From af7b9523b5732e708bf29d1dc8102887eece93b5 Mon Sep 17 00:00:00 2001 From: Artem Baskal Date: Fri, 17 Jan 2020 17:40:47 +0300 Subject: [PATCH 3/3] rewrite using isToday helper --- client/src/components/Logs/index.js | 5 ++--- client/src/helpers/helpers.js | 18 ++++-------------- 2 files changed, 6 insertions(+), 17 deletions(-) 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 {