@zohodesk/i18n 1.0.0-beta.2 → 1.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -5
- package/es/I18NContext.js +1 -2
- package/es/components/DateTimeDiffFormat.js +191 -184
- package/es/components/FormatText.js +4 -25
- package/es/components/HOCI18N.js +33 -45
- package/es/components/I18N.js +46 -63
- package/es/components/I18NProvider.js +54 -84
- package/es/components/PluralFormat.js +29 -48
- package/es/components/UserTimeDiffFormat.js +65 -70
- package/es/components/__tests__/DateTimeDiffFormat.spec.js +868 -657
- package/es/components/__tests__/FormatText.spec.js +20 -17
- package/es/components/__tests__/HOCI18N.spec.js +18 -22
- package/es/components/__tests__/I18N.spec.js +20 -19
- package/es/components/__tests__/I18NProvider.spec.js +36 -45
- package/es/components/__tests__/PluralFormat.spec.js +20 -17
- package/es/components/__tests__/UserTimeDiffFormat.spec.js +1343 -1095
- package/es/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/es/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/es/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/es/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/es/index.js +2 -6
- package/es/utils.js +250 -385
- package/lib/I18NContext.js +6 -6
- package/lib/components/DateTimeDiffFormat.js +166 -123
- package/lib/components/FormatText.js +32 -22
- package/lib/components/HOCI18N.js +47 -23
- package/lib/components/I18N.js +60 -36
- package/lib/components/I18NProvider.js +76 -69
- package/lib/components/PluralFormat.js +42 -32
- package/lib/components/UserTimeDiffFormat.js +81 -54
- package/lib/components/__tests__/DateTimeDiffFormat.spec.js +815 -629
- package/lib/components/__tests__/FormatText.spec.js +23 -25
- package/lib/components/__tests__/HOCI18N.spec.js +26 -34
- package/lib/components/__tests__/I18N.spec.js +21 -26
- package/lib/components/__tests__/I18NProvider.spec.js +43 -51
- package/lib/components/__tests__/PluralFormat.spec.js +24 -28
- package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1256 -1039
- package/lib/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/lib/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/lib/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/lib/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/lib/index.js +73 -119
- package/lib/utils.js +222 -329
- package/package.json +29 -29
- package/src/I18NContext.js +3 -0
- package/src/components/DateTimeDiffFormat.js +256 -0
- package/src/components/FormatText.js +14 -0
- package/src/components/HOCI18N.js +37 -0
- package/src/components/I18N.js +72 -0
- package/src/components/I18NProvider.js +110 -0
- package/src/components/PluralFormat.js +37 -0
- package/src/components/UserTimeDiffFormat.js +97 -0
- package/src/components/__tests__/DateTimeDiffFormat.spec.js +618 -0
- package/src/components/__tests__/FormatText.spec.js +27 -0
- package/src/components/__tests__/HOCI18N.spec.js +33 -0
- package/src/components/__tests__/I18N.spec.js +30 -0
- package/src/components/__tests__/I18NProvider.spec.js +65 -0
- package/src/components/__tests__/PluralFormat.spec.js +28 -0
- package/src/components/__tests__/UserTimeDiffFormat.spec.js +1076 -0
- package/src/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -0
- package/src/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -0
- package/src/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -0
- package/src/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -0
- package/src/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -0
- package/src/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -0
- package/src/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -0
- package/src/index.js +33 -0
- package/src/utils.js +527 -0
- package/.DS_Store +0 -0
- package/es/components/NewDateFormat.js +0 -50
- package/es/offset.js +0 -629
- package/es/timezones.js +0 -112
- package/lib/components/NewDateFormat.js +0 -68
- package/lib/offset.js +0 -634
- package/lib/timezones.js +0 -120
package/es/timezones.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from 'babel-runtime/helpers/slicedToArray';
|
|
2
|
-
function charCodeToInt(charCode) {
|
|
3
|
-
if (charCode > 96) {
|
|
4
|
-
return charCode - 87;
|
|
5
|
-
} else if (charCode > 64) {
|
|
6
|
-
return charCode - 29;
|
|
7
|
-
}
|
|
8
|
-
return charCode - 48;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function unpackBase60(string) {
|
|
12
|
-
var i = 0,
|
|
13
|
-
parts = string.split('.'),
|
|
14
|
-
_parts = _slicedToArray(parts, 1),
|
|
15
|
-
whole = _parts[0],
|
|
16
|
-
fractional = parts[1] || '',
|
|
17
|
-
multiplier = 1,
|
|
18
|
-
num = void 0,
|
|
19
|
-
out = 0,
|
|
20
|
-
sign = 1;
|
|
21
|
-
|
|
22
|
-
// handle negative numbers
|
|
23
|
-
if (string.charCodeAt(0) === 45) {
|
|
24
|
-
i = 1;
|
|
25
|
-
sign = -1;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// handle digits before the decimal
|
|
29
|
-
for (i; i < whole.length; i++) {
|
|
30
|
-
num = charCodeToInt(whole.charCodeAt(i));
|
|
31
|
-
out = 60 * out + num;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// handle digits after the decimal
|
|
35
|
-
for (i = 0; i < fractional.length; i++) {
|
|
36
|
-
multiplier = multiplier / 60;
|
|
37
|
-
num = charCodeToInt(fractional.charCodeAt(i));
|
|
38
|
-
out += num * multiplier;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return out * sign;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function arrayToInt(array) {
|
|
45
|
-
for (var i = 0; i < array.length; i++) {
|
|
46
|
-
array[i] = unpackBase60(array[i]);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function intToUntil(array, length) {
|
|
51
|
-
for (var i = 0; i < length; i++) {
|
|
52
|
-
array[i] = Math.round((array[i - 1] || 0) + array[i] * 60000); // minutes to milliseconds
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
array[length - 1] = Infinity;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function mapIndices(source, indices) {
|
|
59
|
-
var out = [],
|
|
60
|
-
i = void 0;
|
|
61
|
-
|
|
62
|
-
for (i = 0; i < indices.length; i++) {
|
|
63
|
-
out[i] = source[indices[i]];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return out;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function unpack(string) {
|
|
70
|
-
if (string) {
|
|
71
|
-
var data = string.split('|'),
|
|
72
|
-
offsets = data[0].split(' '),
|
|
73
|
-
indices = data[1].split(''),
|
|
74
|
-
untils = data[2].split(' ');
|
|
75
|
-
|
|
76
|
-
arrayToInt(offsets);
|
|
77
|
-
arrayToInt(indices);
|
|
78
|
-
arrayToInt(untils);
|
|
79
|
-
|
|
80
|
-
intToUntil(untils, indices.length);
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
offsets: mapIndices(offsets, indices),
|
|
84
|
-
untils: untils
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
var utcOffset = function utcOffset(timestamp, tzData) {
|
|
90
|
-
var target = +timestamp,
|
|
91
|
-
i = void 0;
|
|
92
|
-
var untils = tzData.untils,
|
|
93
|
-
offsets = tzData.offsets;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
for (i = 0; i < untils.length; i++) {
|
|
97
|
-
var diff = target + offsets[i] * 60000; //minutes to milliseconds
|
|
98
|
-
if (diff < untils[i]) {
|
|
99
|
-
return offsets[i];
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
var getTimezoneOffset = function getTimezoneOffset(timestamp, tzData) {
|
|
105
|
-
var offset = utcOffset(timestamp, tzData);
|
|
106
|
-
if (Math.abs(offset) < 16) {
|
|
107
|
-
offset = offset / 60;
|
|
108
|
-
}
|
|
109
|
-
return -offset;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export { unpack, getTimezoneOffset };
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = NewDateFormat;
|
|
7
|
-
|
|
8
|
-
var _react = require('react');
|
|
9
|
-
|
|
10
|
-
var _react2 = _interopRequireDefault(_react);
|
|
11
|
-
|
|
12
|
-
var _propTypes = require('prop-types');
|
|
13
|
-
|
|
14
|
-
var _propTypes2 = _interopRequireDefault(_propTypes);
|
|
15
|
-
|
|
16
|
-
var _utils = require('../utils');
|
|
17
|
-
|
|
18
|
-
var _FormatText = require('./FormatText');
|
|
19
|
-
|
|
20
|
-
var _FormatText2 = _interopRequireDefault(_FormatText);
|
|
21
|
-
|
|
22
|
-
var _I18NContext = require('../I18NContext');
|
|
23
|
-
|
|
24
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
|
-
function NewDateFormat(props, context) {
|
|
27
|
-
var currentTime = new Date();
|
|
28
|
-
var to = props.to,
|
|
29
|
-
today = props.today,
|
|
30
|
-
yesterday = props.yesterday,
|
|
31
|
-
tomorrow = props.tomorrow,
|
|
32
|
-
others = props.others,
|
|
33
|
-
ago = props.ago,
|
|
34
|
-
later = props.later,
|
|
35
|
-
format = props.format,
|
|
36
|
-
titleFormat = props.titleFormat,
|
|
37
|
-
titleString = props.titleString,
|
|
38
|
-
className = props.className,
|
|
39
|
-
displayType = props.displayType,
|
|
40
|
-
calculateFrom = props.calculateFrom;
|
|
41
|
-
|
|
42
|
-
calculateFrom = calculateFrom === undefined ? currentTime : calculateFrom;
|
|
43
|
-
var tzData = context.tzData;
|
|
44
|
-
|
|
45
|
-
var formatResponse = (0, _utils.getFormatedDate)(to, today, yesterday, tomorrow, others, ago, later, format, titleFormat, titleString, calculateFrom, tzData);
|
|
46
|
-
var isI18nValue = formatResponse.isFormatText;
|
|
47
|
-
if (isI18nValue) {
|
|
48
|
-
var i18nText = formatResponse.i18nText,
|
|
49
|
-
values = formatResponse.values,
|
|
50
|
-
_title = formatResponse.title;
|
|
51
|
-
|
|
52
|
-
return _react2.default.createElement(_FormatText2.default, {
|
|
53
|
-
i18NKey: i18nText,
|
|
54
|
-
values: values,
|
|
55
|
-
className: className,
|
|
56
|
-
'data-title': _title
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
var title = formatResponse.title,
|
|
60
|
-
formatedDate = formatResponse.formatedDate;
|
|
61
|
-
|
|
62
|
-
return _react2.default.createElement(
|
|
63
|
-
'span',
|
|
64
|
-
{ className: className, 'data-title': title },
|
|
65
|
-
formatedDate
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
NewDateFormat.contextType = _I18NContext.I18NContext;
|