- client: Fix beyond 24 hour time format for en locale: Merge pull request #651 in DNS/adguard-home from fix/1766 to master
Close #1766
Squashed commit of the following:
commit 691aa0e30e8435c81118cb5b8784a6902ed10f08
Merge: 67d62fa9 4a81abb9
Author: ArtemBaskal <a.baskal@adguard.com>
Date: Fri Jun 5 13:17:46 2020 +0300
Merge branch 'master' into fix/1766
commit 67d62fa9f8c9e1e7c7db714b85aa19e6b897a2d0
Author: ArtemBaskal <a.baskal@adguard.com>
Date: Fri Jun 5 11:53:47 2020 +0300
Fix jsdocs of helpers
commit 459e3cf8e185033d7e20f0b1d24c6e0146310017
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
This commit is contained in:
parent
4a81abb922
commit
c842a68a1b
|
@ -30,8 +30,8 @@ import {
|
||||||
} from './constants';
|
} from './constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string The time to format
|
* @param time {string} The time to format
|
||||||
* @returns string Returns the time in the format HH:mm:ss
|
* @returns {string} Returns the time in the format HH:mm:ss
|
||||||
*/
|
*/
|
||||||
export const formatTime = (time) => {
|
export const formatTime = (time) => {
|
||||||
const parsedTime = dateParse(time);
|
const parsedTime = dateParse(time);
|
||||||
|
@ -39,23 +39,30 @@ export const formatTime = (time) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string The date to format
|
* @param dateTime {string} The date to format
|
||||||
* @returns string Returns the date and time in the format DD/MM/YYYY, HH:mm
|
* @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) => {
|
export const formatDateTime = (dateTime, options = DEFAULT_DATE_FORMAT_OPTIONS) => {
|
||||||
const currentLanguage = i18n.languages[0] || DEFAULT_LANGUAGE;
|
const { language } = navigator;
|
||||||
const parsedTime = dateParse(dateTime);
|
const currentLanguage = (language.slice(0, 2) === 'en' || !language) ? 'en-GB' : language;
|
||||||
|
|
||||||
|
const parsedTime = new Date(dateTime);
|
||||||
|
|
||||||
return parsedTime.toLocaleString(currentLanguage, options);
|
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(
|
export const formatDetailedDateTime = (dateTime) => formatDateTime(
|
||||||
dateTime, DETAILED_DATE_FORMAT_OPTIONS,
|
dateTime, DETAILED_DATE_FORMAT_OPTIONS,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string
|
* @param date {string}
|
||||||
* @returns boolean
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
export const isToday = (date) => isSameDay(new Date(date), new Date());
|
export const isToday = (date) => isSameDay(new Date(date), new Date());
|
||||||
|
|
||||||
|
@ -307,15 +314,12 @@ export const normalizeTextarea = (text) => {
|
||||||
* @returns {Object.<string, number>} normalizedTopClients.auto - auto clients
|
* @returns {Object.<string, number>} normalizedTopClients.auto - auto clients
|
||||||
* @returns {Object.<string, number>} normalizedTopClients.configured - configured clients
|
* @returns {Object.<string, number>} normalizedTopClients.configured - configured clients
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const normalizeTopClients = (topClients) => topClients.reduce(
|
export const normalizeTopClients = (topClients) => topClients.reduce(
|
||||||
(nameToCountMap, clientObj) => {
|
(acc, clientObj) => {
|
||||||
const { name, count, info: { name: infoName } } = clientObj;
|
const { name, count, info: { name: infoName } } = clientObj;
|
||||||
// eslint-disable-next-line no-param-reassign
|
acc.auto[name] = count;
|
||||||
nameToCountMap.auto[name] = count;
|
acc.configured[infoName] = count;
|
||||||
// eslint-disable-next-line no-param-reassign
|
return acc;
|
||||||
nameToCountMap.configured[infoName] = count;
|
|
||||||
return nameToCountMap;
|
|
||||||
}, {
|
}, {
|
||||||
auto: {},
|
auto: {},
|
||||||
configured: {},
|
configured: {},
|
||||||
|
@ -483,8 +487,8 @@ export const getCurrentFilter = (url, filters) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {object} initialValues
|
* @param initialValues {object}
|
||||||
* @param {object} values
|
* @param values {object}
|
||||||
* @returns {object} Returns different values of objects
|
* @returns {object} Returns different values of objects
|
||||||
*/
|
*/
|
||||||
export const getObjDiff = (initialValues, values) => Object.entries(values)
|
export const getObjDiff = (initialValues, values) => Object.entries(values)
|
||||||
|
@ -496,8 +500,8 @@ export const getObjDiff = (initialValues, values) => Object.entries(values)
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param number Number to format
|
* @param num {number} to format
|
||||||
* @returns string Returns a string with a language-sensitive representation of this number
|
* @returns {string} Returns a string with a language-sensitive representation of this number
|
||||||
*/
|
*/
|
||||||
export const formatNumber = (num) => {
|
export const formatNumber = (num) => {
|
||||||
const currentLanguage = i18n.languages[0] || DEFAULT_LANGUAGE;
|
const currentLanguage = i18n.languages[0] || DEFAULT_LANGUAGE;
|
||||||
|
@ -508,7 +512,6 @@ export const normalizeMultiline = (multiline) => `${normalizeTextarea(multiline)
|
||||||
.map((line) => line.trim())
|
.map((line) => line.trim())
|
||||||
.join('\n')}\n`;
|
.join('\n')}\n`;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param parsedIp {object} ipaddr.js IPv4 or IPv6 object
|
* @param parsedIp {object} ipaddr.js IPv4 or IPv6 object
|
||||||
* @param cidr {array} ipaddr.js CIDR array
|
* @param cidr {array} ipaddr.js CIDR array
|
||||||
|
|
Loading…
Reference in New Issue