@zohodesk/i18n 1.0.0-beta.3 → 1.0.0-beta.31
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 +120 -2
- package/es/I18NContext.js +1 -2
- package/es/components/DateTimeDiffFormat.js +192 -200
- package/es/components/FormatText.js +4 -25
- package/es/components/HOCI18N.js +33 -45
- package/es/components/I18N.js +48 -63
- package/es/components/I18NProvider.js +60 -85
- package/es/components/PluralFormat.js +29 -48
- package/es/components/UserTimeDiffFormat.js +65 -74
- 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/index.js +2 -6
- package/es/utils/__tests__/jsxTranslations.spec.js +174 -0
- package/es/utils/index.js +592 -0
- package/es/utils/jsxTranslations.js +193 -0
- package/lib/I18NContext.js +6 -6
- package/lib/components/DateTimeDiffFormat.js +151 -123
- package/lib/components/FormatText.js +32 -22
- package/lib/components/HOCI18N.js +47 -23
- package/lib/components/I18N.js +62 -36
- package/lib/components/I18NProvider.js +85 -72
- package/lib/components/PluralFormat.js +42 -32
- package/lib/components/UserTimeDiffFormat.js +79 -56
- 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/index.js +85 -110
- package/lib/utils/__tests__/jsxTranslations.spec.js +183 -0
- package/lib/utils/index.js +658 -0
- package/lib/utils/jsxTranslations.js +242 -0
- package/package.json +3 -2
- package/src/components/DateTimeDiffFormat.js +86 -55
- package/src/components/I18N.js +2 -0
- package/src/components/I18NProvider.js +44 -33
- package/src/components/UserTimeDiffFormat.js +24 -18
- package/src/index.js +7 -9
- package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
- package/src/utils/index.js +632 -0
- package/src/utils/jsxTranslations.js +180 -0
- package/es/components/NewDateFormat.js +0 -50
- package/es/offset.js +0 -629
- package/es/timezones.js +0 -118
- package/es/utils.js +0 -621
- package/lib/components/NewDateFormat.js +0 -68
- package/lib/offset.js +0 -634
- package/lib/timezones.js +0 -129
- package/lib/utils.js +0 -651
- package/src/components/NewDateFormat.js +0 -60
- package/src/offset.js +0 -629
- package/src/timezones.js +0 -113
- package/src/utils.js +0 -648
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createElement = createElement;
|
|
7
|
+
exports.generateChildren = generateChildren;
|
|
8
|
+
exports.getI18NComponent = getI18NComponent;
|
|
9
|
+
exports.prepareI18NFunc = prepareI18NFunc;
|
|
10
|
+
exports.replaceWithComponentPlaceHolder = replaceWithComponentPlaceHolder;
|
|
11
|
+
exports.splitMatchedExp = splitMatchedExp;
|
|
12
|
+
|
|
13
|
+
var _react = _interopRequireDefault(require("react"));
|
|
14
|
+
|
|
15
|
+
var _index = require("./index");
|
|
16
|
+
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
18
|
+
|
|
19
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
20
|
+
|
|
21
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
22
|
+
|
|
23
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
24
|
+
|
|
25
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
26
|
+
|
|
27
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
28
|
+
|
|
29
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
30
|
+
|
|
31
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
32
|
+
|
|
33
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
34
|
+
|
|
35
|
+
function splitMatchedExp(_ref) {
|
|
36
|
+
var expression = _ref.expression,
|
|
37
|
+
charLenToOmit = _ref.charLenToOmit,
|
|
38
|
+
string = _ref.string;
|
|
39
|
+
var splitString = string.split(new RegExp(expression, 'g'));
|
|
40
|
+
var matchedExpAll = string.matchAll(new RegExp(expression, 'g'));
|
|
41
|
+
var matchedExpKeys = [];
|
|
42
|
+
|
|
43
|
+
var _iterator = _createForOfIteratorHelper(matchedExpAll),
|
|
44
|
+
_step;
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
48
|
+
var match = _step.value;
|
|
49
|
+
var value = match[0];
|
|
50
|
+
matchedExpKeys.push(value.substring(charLenToOmit, value.length - charLenToOmit));
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
_iterator.e(err);
|
|
54
|
+
} finally {
|
|
55
|
+
_iterator.f();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
splitString: splitString,
|
|
60
|
+
matchedExpKeys: matchedExpKeys
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function generateChildren(_ref2) {
|
|
65
|
+
var children = _ref2.children,
|
|
66
|
+
child = _ref2.child;
|
|
67
|
+
var newChildren = [],
|
|
68
|
+
stringPlaceHolders = {};
|
|
69
|
+
|
|
70
|
+
var handleString = function handleString(string) {
|
|
71
|
+
if (string) {
|
|
72
|
+
var _splitMatchedExp = splitMatchedExp({
|
|
73
|
+
expression: '{[0-9]+?}',
|
|
74
|
+
charLenToOmit: 1,
|
|
75
|
+
string: string
|
|
76
|
+
}),
|
|
77
|
+
splitString = _splitMatchedExp.splitString,
|
|
78
|
+
matchedExpKeys = _splitMatchedExp.matchedExpKeys;
|
|
79
|
+
|
|
80
|
+
stringPlaceHolders[newChildren.length] = matchedExpKeys;
|
|
81
|
+
newChildren.push(splitString);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
var _splitMatchedExp2 = splitMatchedExp({
|
|
86
|
+
expression: '<[A-Za-z0-9]+?>',
|
|
87
|
+
charLenToOmit: 1,
|
|
88
|
+
string: child
|
|
89
|
+
}),
|
|
90
|
+
splitChild = _splitMatchedExp2.splitString,
|
|
91
|
+
childrenKeys = _splitMatchedExp2.matchedExpKeys;
|
|
92
|
+
|
|
93
|
+
childrenKeys.forEach(function (childKey, childIndex) {
|
|
94
|
+
var matchedChild = splitChild[childIndex];
|
|
95
|
+
handleString(matchedChild);
|
|
96
|
+
newChildren.push(children[childKey]);
|
|
97
|
+
});
|
|
98
|
+
handleString(splitChild[childrenKeys.length]);
|
|
99
|
+
return {
|
|
100
|
+
newChildren: newChildren,
|
|
101
|
+
stringPlaceHolders: stringPlaceHolders
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function createElement() {
|
|
106
|
+
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
107
|
+
componentId = _ref3.componentId,
|
|
108
|
+
_ref3$children = _ref3.children,
|
|
109
|
+
children = _ref3$children === void 0 ? [] : _ref3$children,
|
|
110
|
+
_ref3$stringPlaceHold = _ref3.stringPlaceHolders,
|
|
111
|
+
stringPlaceHolders = _ref3$stringPlaceHold === void 0 ? {} : _ref3$stringPlaceHold;
|
|
112
|
+
|
|
113
|
+
return function () {
|
|
114
|
+
var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
115
|
+
_ref4$components = _ref4.components,
|
|
116
|
+
components = _ref4$components === void 0 ? {} : _ref4$components,
|
|
117
|
+
_ref4$values = _ref4.values,
|
|
118
|
+
values = _ref4$values === void 0 ? [] : _ref4$values;
|
|
119
|
+
|
|
120
|
+
var _ref5 = components[componentId] || {},
|
|
121
|
+
_ref5$type = _ref5.type,
|
|
122
|
+
type = _ref5$type === void 0 ? _react["default"].Fragment : _ref5$type,
|
|
123
|
+
props = _ref5.props;
|
|
124
|
+
|
|
125
|
+
var childElements = children.map(function (child, index) {
|
|
126
|
+
if (typeof child === 'function') {
|
|
127
|
+
return child({
|
|
128
|
+
components: components,
|
|
129
|
+
values: values
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
var string = '',
|
|
134
|
+
stringIndex = 0;
|
|
135
|
+
(stringPlaceHolders[index] || []).map(function (stringId, index) {
|
|
136
|
+
if (child[index]) {
|
|
137
|
+
string += child[index];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
string += values[stringId];
|
|
141
|
+
stringIndex++;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
if (child[stringIndex]) {
|
|
145
|
+
string += child[stringIndex];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return string;
|
|
149
|
+
});
|
|
150
|
+
return /*#__PURE__*/_react["default"].createElement.apply(_react["default"], [type, props].concat(_toConsumableArray(childElements)));
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
;
|
|
155
|
+
|
|
156
|
+
function replaceWithComponentPlaceHolder(_ref6) {
|
|
157
|
+
var componentId = _ref6.componentId,
|
|
158
|
+
i18nKey = _ref6.i18nKey,
|
|
159
|
+
childrenLength = _ref6.childrenLength;
|
|
160
|
+
var closingTagIndex = i18nKey.indexOf("</".concat(componentId, ">"));
|
|
161
|
+
var childWithOpenTag = i18nKey.substring(0, closingTagIndex);
|
|
162
|
+
var openTagIndex = childWithOpenTag.lastIndexOf("<".concat(componentId, ">"));
|
|
163
|
+
return i18nKey.substring(0, openTagIndex) + "<0".concat(childrenLength).concat(componentId, ">") + i18nKey.substring(closingTagIndex + "".concat(componentId).length + 3);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function prepareI18NFunc() {
|
|
167
|
+
var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
168
|
+
i18nKey = _ref7.i18nKey,
|
|
169
|
+
_ref7$children = _ref7.children,
|
|
170
|
+
children = _ref7$children === void 0 ? {} : _ref7$children;
|
|
171
|
+
|
|
172
|
+
var componentIdMatch = i18nKey.match(/<\/[A-Za-z0-9]+?>/);
|
|
173
|
+
|
|
174
|
+
if (componentIdMatch) {
|
|
175
|
+
var componentId = componentIdMatch[0].substring(2, componentIdMatch[0].length - 1);
|
|
176
|
+
var childWithOpenTag = (i18nKey.match(new RegExp("(.*?)(?=</".concat(componentId, ">)"))) || [])[0] || '';
|
|
177
|
+
var child = childWithOpenTag.split("<".concat(componentId, ">")).pop();
|
|
178
|
+
|
|
179
|
+
var _generateChildren = generateChildren({
|
|
180
|
+
children: children,
|
|
181
|
+
child: child
|
|
182
|
+
}),
|
|
183
|
+
_newChildren = _generateChildren.newChildren,
|
|
184
|
+
_stringPlaceHolders = _generateChildren.stringPlaceHolders;
|
|
185
|
+
|
|
186
|
+
var childrenLength = Object.keys(children).length;
|
|
187
|
+
children["0".concat(childrenLength).concat(componentId)] = createElement({
|
|
188
|
+
componentId: componentId,
|
|
189
|
+
children: _newChildren,
|
|
190
|
+
stringPlaceHolders: _stringPlaceHolders
|
|
191
|
+
});
|
|
192
|
+
i18nKey = replaceWithComponentPlaceHolder({
|
|
193
|
+
componentId: componentId,
|
|
194
|
+
i18nKey: i18nKey,
|
|
195
|
+
childrenLength: childrenLength
|
|
196
|
+
});
|
|
197
|
+
return prepareI18NFunc({
|
|
198
|
+
i18nKey: i18nKey,
|
|
199
|
+
children: children
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
var _generateChildren2 = generateChildren({
|
|
204
|
+
child: i18nKey,
|
|
205
|
+
children: children
|
|
206
|
+
}),
|
|
207
|
+
newChildren = _generateChildren2.newChildren,
|
|
208
|
+
stringPlaceHolders = _generateChildren2.stringPlaceHolders;
|
|
209
|
+
|
|
210
|
+
return createElement({
|
|
211
|
+
componentId: -1,
|
|
212
|
+
children: newChildren,
|
|
213
|
+
stringPlaceHolders: stringPlaceHolders
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function getI18NComponent(i18n) {
|
|
218
|
+
if (typeof i18n === 'undefined') {
|
|
219
|
+
return function (key) {
|
|
220
|
+
return key;
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return function (key) {
|
|
225
|
+
var i18nStr = i18n[key];
|
|
226
|
+
|
|
227
|
+
if (i18nStr === undefined) {
|
|
228
|
+
return key;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (typeof i18nStr === 'string') {
|
|
232
|
+
i18nStr = (0, _index.unescapeUnicode)(i18nStr);
|
|
233
|
+
var value = prepareI18NFunc({
|
|
234
|
+
i18nKey: i18nStr
|
|
235
|
+
});
|
|
236
|
+
window.loadI18nChunk && window.loadI18nChunk(_defineProperty({}, key, value));
|
|
237
|
+
i18nStr = value;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return i18nStr;
|
|
241
|
+
};
|
|
242
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zohodesk/i18n",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.31",
|
|
4
4
|
"main": "lib/index",
|
|
5
5
|
"module": "es/index.js",
|
|
6
6
|
"jsnext:main": "es/index.js",
|
|
@@ -15,11 +15,12 @@
|
|
|
15
15
|
"build:dev": "npm run clean && npm run build --module:mode=dev -- -w",
|
|
16
16
|
"prepublish": "npm run init && npm run build && npm run build:es ",
|
|
17
17
|
"prepare": "npm run init && npm run build && npm run build:es",
|
|
18
|
+
"test": "react-cli test",
|
|
18
19
|
"init": "npm run clean",
|
|
19
20
|
"lint": "react-cli lint"
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"@zoho/SecurityJS": "
|
|
23
|
+
"@zoho/SecurityJS": "6.4.2"
|
|
23
24
|
},
|
|
24
25
|
"react-cli": {
|
|
25
26
|
"docs": {
|
|
@@ -6,9 +6,10 @@ import {
|
|
|
6
6
|
getDiffObj,
|
|
7
7
|
formatDate,
|
|
8
8
|
getLyears,
|
|
9
|
-
|
|
9
|
+
getDatePatternWithoutYear,
|
|
10
10
|
} from '../utils';
|
|
11
11
|
import FormatText from './FormatText';
|
|
12
|
+
import datetime from '@zohodesk/datetimejs';
|
|
12
13
|
export default class DateTimeDiffFormat extends React.Component {
|
|
13
14
|
constructor(props) {
|
|
14
15
|
super(props);
|
|
@@ -30,6 +31,8 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
30
31
|
render() {
|
|
31
32
|
const {
|
|
32
33
|
type,
|
|
34
|
+
page,
|
|
35
|
+
isNeedTime,
|
|
33
36
|
from,
|
|
34
37
|
fromTzData,
|
|
35
38
|
to,
|
|
@@ -42,11 +45,19 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
42
45
|
dataId,
|
|
43
46
|
className = null,
|
|
44
47
|
title = null,
|
|
45
|
-
isOverdue
|
|
48
|
+
isOverdue,
|
|
49
|
+
timeFormat,
|
|
50
|
+
datePattern,
|
|
51
|
+
isEnabledCurrentYear,
|
|
52
|
+
isDateField
|
|
46
53
|
} = this.props;
|
|
47
54
|
|
|
48
|
-
let fromDateObj =
|
|
49
|
-
|
|
55
|
+
let fromDateObj = datetime
|
|
56
|
+
.toDate(datetime.tz.utcToTz(from, fromTzData))
|
|
57
|
+
.getTime();
|
|
58
|
+
let toDateObj = datetime
|
|
59
|
+
.toDate(isDateField ? to : datetime.tz.utcToTz(to, toTzData))
|
|
60
|
+
.getTime();
|
|
50
61
|
|
|
51
62
|
let diffMin = new Date(to).getTime() - new Date(from).getTime();
|
|
52
63
|
let suffix = this.getSuffix(diffMin);
|
|
@@ -65,16 +76,18 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
65
76
|
days: diff.yd,
|
|
66
77
|
yDays: pad(diff.yd, 2),
|
|
67
78
|
isWithInAWeek: withInAWeak,
|
|
68
|
-
suffix: suffix
|
|
79
|
+
suffix: suffix,
|
|
69
80
|
};
|
|
70
81
|
let diffObj1 = {
|
|
82
|
+
to: to,
|
|
71
83
|
type: type,
|
|
84
|
+
page: page,
|
|
85
|
+
isNeedTime: isNeedTime,
|
|
72
86
|
hours: diff.h,
|
|
73
87
|
minutes: diff.m,
|
|
74
88
|
seconds: diff.s,
|
|
75
89
|
years: diff.y,
|
|
76
90
|
yDays: diff.yd,
|
|
77
|
-
yMonth: diff.m,
|
|
78
91
|
isWithInAWeek: withInAWeak,
|
|
79
92
|
suffix: suffix,
|
|
80
93
|
crntDate: new Date(from).getDate(),
|
|
@@ -90,9 +103,27 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
90
103
|
tMinutes: new Date(to).getMinutes(),
|
|
91
104
|
tSeconds: new Date(to).getSeconds(),
|
|
92
105
|
betweenleepYears: getLyears(from, to),
|
|
93
|
-
isOverdue: isOverdue
|
|
106
|
+
isOverdue: isOverdue,
|
|
107
|
+
timeFormat: timeFormat,
|
|
108
|
+
datePattern: datePattern,
|
|
109
|
+
dateTimePattern: `${datePattern} ${timeFormat}`,
|
|
94
110
|
};
|
|
95
111
|
|
|
112
|
+
//In if condition we'll remove year and set date format if the current year is not required
|
|
113
|
+
//In else part we'll set the date format as it is
|
|
114
|
+
if (
|
|
115
|
+
isEnabledCurrentYear === true &&
|
|
116
|
+
diffObj1.years === 0 &&
|
|
117
|
+
diffObj1.tYear === diffObj1.crntYear
|
|
118
|
+
) {
|
|
119
|
+
let dateFormat = getDatePatternWithoutYear(datePattern);
|
|
120
|
+
diffObj1.dateFormat = dateFormat;
|
|
121
|
+
diffObj1.dateTimeFormat = `${dateFormat} ${timeFormat}`;
|
|
122
|
+
} else {
|
|
123
|
+
diffObj1.dateFormat = datePattern;
|
|
124
|
+
diffObj1.dateTimeFormat = `${datePattern} ${timeFormat}`;
|
|
125
|
+
}
|
|
126
|
+
|
|
96
127
|
let key = '';
|
|
97
128
|
let values = [];
|
|
98
129
|
let text = null;
|
|
@@ -132,57 +163,56 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
132
163
|
text = formatDate(toDateObj, value, diffObj1);
|
|
133
164
|
}
|
|
134
165
|
} else {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
} else if (
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
} else if (dateObj.getDate() > curDateObj.getDate()) {
|
|
162
|
-
if (typeof tomorrow === 'function') {
|
|
163
|
-
var value = tomorrow(diffObj1);
|
|
164
|
-
key = value.key;
|
|
165
|
-
text = getValues(value.params, diffObj);
|
|
166
|
-
} else if (typeof tomorrow === 'object') {
|
|
167
|
-
key = tomorrow.key;
|
|
168
|
-
values = getValues(tomorrow.params, diffObj);
|
|
169
|
-
} else if (typeof tomorrow === 'string') {
|
|
170
|
-
text = formatDate(toDateObj, tomorrow);
|
|
166
|
+
let dateObj = new Date(toDateObj);
|
|
167
|
+
let curDateObj = new Date(fromDateObj);
|
|
168
|
+
let diffDayType = diffObj1.yDays;
|
|
169
|
+
|
|
170
|
+
//In this condition, to calculate different days we have copied it from live --> diffDayType
|
|
171
|
+
if (
|
|
172
|
+
isOverdue &&
|
|
173
|
+
dateObj.getDate() < curDateObj.getDate() &&
|
|
174
|
+
diffObj1.yDays == 0
|
|
175
|
+
) {
|
|
176
|
+
diffDayType = -1;
|
|
177
|
+
}
|
|
178
|
+
if (!isOverdue) {
|
|
179
|
+
let diffHr = dateObj.getHours() - curDateObj.getHours();
|
|
180
|
+
if (diffHr < 0) {
|
|
181
|
+
diffDayType += 1;
|
|
182
|
+
} else if (diffHr == 0) {
|
|
183
|
+
let diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
|
|
184
|
+
if (diffMins < 0) {
|
|
185
|
+
diffDayType += 1;
|
|
186
|
+
} else if (diffMins == 0) {
|
|
187
|
+
let diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
|
|
188
|
+
if (diffSec < 0) {
|
|
189
|
+
diffDayType += 1;
|
|
190
|
+
}
|
|
171
191
|
}
|
|
172
192
|
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
193
|
+
}
|
|
194
|
+
if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
|
|
195
|
+
if (dateObj.getDate() === curDateObj.getDate()) {
|
|
196
|
+
var value = (today && today(diffObj1)) || others(diffObj1);
|
|
197
|
+
text = formatDate(toDateObj, value);
|
|
198
|
+
} else if (
|
|
199
|
+
(dateObj.getMonth() === curDateObj.getMonth() &&
|
|
200
|
+
dateObj.getDate() < curDateObj.getDate()) ||
|
|
201
|
+
dateObj.getMonth() < curDateObj.getMonth()
|
|
202
|
+
) {
|
|
203
|
+
var value = (yesterday && yesterday(diffObj1)) || others(diffObj1);
|
|
204
|
+
text = formatDate(toDateObj, value);
|
|
205
|
+
} else if (!isOverdue && diff.y === 0 && diffDayType === 1) {
|
|
206
|
+
var value = (tomorrow && tomorrow(diffObj1)) || others(diffObj1);
|
|
180
207
|
text = formatDate(toDateObj, value);
|
|
181
208
|
}
|
|
209
|
+
} else {
|
|
210
|
+
var value = others(diffObj1);
|
|
211
|
+
text = formatDate(toDateObj, value);
|
|
182
212
|
}
|
|
183
213
|
}
|
|
184
214
|
return text ? (
|
|
185
|
-
<span className={className} data-title={title} data-id={dataId}>
|
|
215
|
+
<span className={className} data-title={title} data-id={dataId} data-test-id={dataId}>
|
|
186
216
|
{text}
|
|
187
217
|
</span>
|
|
188
218
|
) : (
|
|
@@ -202,6 +232,7 @@ DateTimeDiffFormat.propTypes = {
|
|
|
202
232
|
format: PropTypes.func,
|
|
203
233
|
from: PropTypes.string,
|
|
204
234
|
fromTzData: PropTypes.object,
|
|
235
|
+
isDateField: PropTypes.bool,
|
|
205
236
|
later: PropTypes.string,
|
|
206
237
|
others: PropTypes.func,
|
|
207
238
|
title: PropTypes.string,
|
|
@@ -210,16 +241,16 @@ DateTimeDiffFormat.propTypes = {
|
|
|
210
241
|
today: PropTypes.oneOfType([
|
|
211
242
|
PropTypes.string,
|
|
212
243
|
PropTypes.object,
|
|
213
|
-
PropTypes.func
|
|
244
|
+
PropTypes.func,
|
|
214
245
|
]),
|
|
215
246
|
tomorrow: PropTypes.oneOfType([
|
|
216
247
|
PropTypes.string,
|
|
217
248
|
PropTypes.object,
|
|
218
|
-
PropTypes.func
|
|
249
|
+
PropTypes.func,
|
|
219
250
|
]),
|
|
220
251
|
yesterday: PropTypes.oneOfType([
|
|
221
252
|
PropTypes.string,
|
|
222
253
|
PropTypes.object,
|
|
223
|
-
PropTypes.func
|
|
224
|
-
])
|
|
254
|
+
PropTypes.func,
|
|
255
|
+
]),
|
|
225
256
|
};
|
package/src/components/I18N.js
CHANGED
|
@@ -41,6 +41,7 @@ export default class I18N extends React.Component {
|
|
|
41
41
|
//const child=this.getI18NValue();
|
|
42
42
|
if (this.props.dataId) {
|
|
43
43
|
props['data-id'] = this.props.dataId;
|
|
44
|
+
props['data-test-id'] = this.props.dataId;
|
|
44
45
|
}
|
|
45
46
|
if (this.props.isHtml) {
|
|
46
47
|
let dangerouslySetInnerHTML = {
|
|
@@ -63,6 +64,7 @@ I18N.propTypes = {
|
|
|
63
64
|
i18NKey: PropTypes.string.isRequired,
|
|
64
65
|
isHtml: PropTypes.bool,
|
|
65
66
|
tag: PropTypes.string,
|
|
67
|
+
dataId: PropTypes.string,
|
|
66
68
|
values: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
|
|
67
69
|
};
|
|
68
70
|
I18N.defaultProps = {
|
|
@@ -1,61 +1,72 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { getI18NValue, userDateFormat } from '../utils';
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
getI18NComponent
|
|
6
|
+
} from '../utils/jsxTranslations';
|
|
6
7
|
import { I18NContext } from '../I18NContext';
|
|
7
8
|
|
|
8
9
|
const emptyObj = {};
|
|
9
10
|
const dummy = (key, values) => key;
|
|
10
|
-
|
|
11
|
-
[tzStr => tzStr],
|
|
12
|
-
tzStr => unpack(tzStr)
|
|
13
|
-
);
|
|
11
|
+
|
|
14
12
|
export const i18NProviderUtils = {
|
|
15
13
|
getI18NValue: dummy,
|
|
16
|
-
userDateFormat: dummy
|
|
14
|
+
userDateFormat: dummy,
|
|
15
|
+
getI18NComponent: dummy
|
|
17
16
|
};
|
|
18
17
|
|
|
19
18
|
export default class I18NProvider extends React.Component {
|
|
20
19
|
constructor(props, context) {
|
|
21
20
|
super(props, context);
|
|
22
21
|
i18NProviderUtils.getI18NValue = getI18NValue(props.i18n);
|
|
23
|
-
i18NProviderUtils.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
i18NProviderUtils.getI18NComponent = getI18NComponent(props.i18n);
|
|
23
|
+
if(props.tzData){
|
|
24
|
+
i18NProviderUtils.userDateFormat = userDateFormat(
|
|
25
|
+
i18NProviderUtils.getI18NValue,
|
|
26
|
+
props.tzData,
|
|
27
|
+
props.timeFormat,
|
|
28
|
+
props.datePattern,
|
|
29
|
+
props.isEnabledCurrentYear
|
|
30
|
+
);
|
|
31
|
+
}
|
|
27
32
|
}
|
|
28
33
|
|
|
29
|
-
componentDidUpdate(
|
|
34
|
+
componentDidUpdate(prevProps) {
|
|
30
35
|
let {
|
|
31
36
|
i18n,
|
|
32
37
|
timeZone,
|
|
33
38
|
datePattern,
|
|
34
39
|
timeFormat,
|
|
35
|
-
dateTimeFormat,
|
|
36
40
|
direction,
|
|
37
41
|
onChange,
|
|
38
|
-
tzData
|
|
42
|
+
tzData,
|
|
43
|
+
isEnabledCurrentYear
|
|
39
44
|
} = this.props;
|
|
40
45
|
if (
|
|
41
|
-
i18n !==
|
|
42
|
-
timeZone !==
|
|
43
|
-
datePattern !==
|
|
44
|
-
timeFormat !==
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
i18n !== prevProps.i18n ||
|
|
47
|
+
timeZone !== prevProps.timeZone ||
|
|
48
|
+
datePattern !== prevProps.datePattern ||
|
|
49
|
+
timeFormat !== prevProps.timeFormat ||
|
|
50
|
+
direction !== prevProps.direction ||
|
|
51
|
+
tzData !== prevProps.tzData ||
|
|
52
|
+
isEnabledCurrentYear !== prevProps.isEnabledCurrentYear
|
|
48
53
|
) {
|
|
49
54
|
this.promise = new Promise((res, rej) => {
|
|
50
55
|
this.resolve = res;
|
|
51
56
|
this.reject = rej;
|
|
52
57
|
}).then(
|
|
53
58
|
() => {
|
|
54
|
-
i18NProviderUtils.getI18NValue = getI18NValue(
|
|
55
|
-
i18NProviderUtils.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
i18NProviderUtils.getI18NValue = getI18NValue(this.props.i18n);
|
|
60
|
+
i18NProviderUtils.getI18NComponent = getI18NComponent(this.props.i18n);
|
|
61
|
+
if (this.props.tzData) {
|
|
62
|
+
i18NProviderUtils.userDateFormat = userDateFormat(
|
|
63
|
+
i18NProviderUtils.getI18NValue,
|
|
64
|
+
this.props.tzData,
|
|
65
|
+
this.props.timeFormat,
|
|
66
|
+
this.props.datePattern,
|
|
67
|
+
this.props.isEnabledCurrentYear
|
|
68
|
+
);
|
|
69
|
+
}
|
|
59
70
|
this.promise = null;
|
|
60
71
|
},
|
|
61
72
|
() => {
|
|
@@ -73,10 +84,10 @@ export default class I18NProvider extends React.Component {
|
|
|
73
84
|
i18n: this.props.i18n,
|
|
74
85
|
direction: this.props.direction,
|
|
75
86
|
timeZone: this.props.timeZone,
|
|
76
|
-
tzData: getTzData(this.props.tzData),
|
|
77
87
|
datePattern: this.props.datePattern,
|
|
78
88
|
timeFormat: this.props.timeFormat,
|
|
79
|
-
|
|
89
|
+
isEnabledCurrentYear: this.props.isEnabledCurrentYear,
|
|
90
|
+
tzData: this.props.tzData,
|
|
80
91
|
}}
|
|
81
92
|
>
|
|
82
93
|
{this.props.children}
|
|
@@ -90,18 +101,18 @@ I18NProvider.defaultProps = {
|
|
|
90
101
|
timeZone: '',
|
|
91
102
|
datePattern: '',
|
|
92
103
|
timeFormat: '',
|
|
93
|
-
|
|
94
|
-
direction: 'ltr'
|
|
104
|
+
isEnabledCurrentYear: '',
|
|
105
|
+
direction: 'ltr',
|
|
95
106
|
};
|
|
96
107
|
|
|
97
108
|
I18NProvider.propTypes = {
|
|
98
109
|
children: PropTypes.element.isRequired,
|
|
99
110
|
datePattern: PropTypes.string,
|
|
100
|
-
|
|
111
|
+
isEnabledCurrentYear: PropTypes.string,
|
|
101
112
|
direction: PropTypes.string,
|
|
102
113
|
i18n: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
|
103
114
|
onChange: PropTypes.func,
|
|
104
115
|
timeFormat: PropTypes.string,
|
|
105
116
|
timeZone: PropTypes.string,
|
|
106
|
-
tzData: PropTypes.
|
|
107
|
-
};
|
|
117
|
+
tzData: PropTypes.object,
|
|
118
|
+
};
|