Skip to content

Commit

Permalink
- client: Fix beyond 24 hour time format for en locale: Merge pull re…
Browse files Browse the repository at this point in the history
…quest #651 in DNS/adguard-home from fix/1766 to master

Close #1766

Squashed commit of the following:

commit 691aa0e
Merge: 67d62fa 4a81abb
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Fri Jun 5 13:17:46 2020 +0300

    Merge branch 'master' into fix/1766

commit 67d62fa
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Fri Jun 5 11:53:47 2020 +0300

    Fix jsdocs of helpers

commit 459e3cf
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Thu Jun 4 20:45:17 2020 +0300

    - client: Fix beyond 24 hour time format for en locale
  • Loading branch information
ArtemBaskal committed Jun 5, 2020
1 parent 4a81abb commit c842a68
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions client/src/helpers/helpers.js
Expand Up @@ -30,32 +30,39 @@ import {
} from './constants';

/**
* @param string The time to format
* @returns string Returns the time in the format HH:mm:ss
* @param time {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, DEFAULT_TIME_FORMAT);
};

/**
* @param string The date to format
* @returns string Returns the date and time in the format DD/MM/YYYY, HH:mm
* @param dateTime {string} The date to format
* @param [options] {object} Date.prototype.toLocaleString([locales[, options]]) options argument
* @returns {string} Returns the date and time in the specified format
*/
export const formatDateTime = (dateTime, options = DEFAULT_DATE_FORMAT_OPTIONS) => {
const currentLanguage = i18n.languages[0] || DEFAULT_LANGUAGE;
const parsedTime = dateParse(dateTime);
const { language } = navigator;
const currentLanguage = (language.slice(0, 2) === 'en' || !language) ? 'en-GB' : language;

const parsedTime = new Date(dateTime);

return parsedTime.toLocaleString(currentLanguage, options);
};

/**
* @param dateTime {string} The date to format
* @returns {string} Returns the date and time in the format with the full month name
*/
export const formatDetailedDateTime = (dateTime) => formatDateTime(
dateTime, DETAILED_DATE_FORMAT_OPTIONS,
);

/**
* @param string
* @returns boolean
* @param date {string}
* @returns {boolean}
*/
export const isToday = (date) => isSameDay(new Date(date), new Date());

Expand Down Expand Up @@ -307,15 +314,12 @@ export const normalizeTextarea = (text) => {
* @returns {Object.<string, number>} normalizedTopClients.auto - auto clients
* @returns {Object.<string, number>} normalizedTopClients.configured - configured clients
*/

export const normalizeTopClients = (topClients) => topClients.reduce(
(nameToCountMap, clientObj) => {
(acc, clientObj) => {
const { name, count, info: { name: infoName } } = clientObj;
// eslint-disable-next-line no-param-reassign
nameToCountMap.auto[name] = count;
// eslint-disable-next-line no-param-reassign
nameToCountMap.configured[infoName] = count;
return nameToCountMap;
acc.auto[name] = count;
acc.configured[infoName] = count;
return acc;
}, {
auto: {},
configured: {},
Expand Down Expand Up @@ -483,8 +487,8 @@ export const getCurrentFilter = (url, filters) => {
};

/**
* @param {object} initialValues
* @param {object} values
* @param initialValues {object}
* @param values {object}
* @returns {object} Returns different values of objects
*/
export const getObjDiff = (initialValues, values) => Object.entries(values)
Expand All @@ -496,8 +500,8 @@ export const getObjDiff = (initialValues, values) => Object.entries(values)
}, {});

/**
* @param number Number to format
* @returns string Returns a string with a language-sensitive representation of this number
* @param num {number} to format
* @returns {string} Returns a string with a language-sensitive representation of this number
*/
export const formatNumber = (num) => {
const currentLanguage = i18n.languages[0] || DEFAULT_LANGUAGE;
Expand All @@ -508,7 +512,6 @@ export const normalizeMultiline = (multiline) => `${normalizeTextarea(multiline)
.map((line) => line.trim())
.join('\n')}\n`;


/**
* @param parsedIp {object} ipaddr.js IPv4 or IPv6 object
* @param cidr {array} ipaddr.js CIDR array
Expand Down

0 comments on commit c842a68

Please sign in to comment.