@zohodesk/i18n 1.0.0-beta.4 → 1.0.0-beta.41-murphy

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.
Files changed (70) hide show
  1. package/README.md +130 -4
  2. package/docs/murphy/01-MURPHY_OVERVIEW.md +148 -0
  3. package/docs/murphy/02-MURPHY_ARCHITECTURE.md +283 -0
  4. package/docs/murphy/03-MURPHY_BACKEND_CONFIG.md +337 -0
  5. package/docs/murphy/04-MURPHY_FRONTEND_INIT.md +437 -0
  6. package/docs/murphy/05-MURPHY_DESK_CLIENT_USAGE.md +467 -0
  7. package/docs/murphy/06-MURPHY_I18N_INTEGRATION.md +402 -0
  8. package/docs/murphy/07-MURPHY_WHY_I18N_APPROACH.md +391 -0
  9. package/es/I18NContext.js +1 -2
  10. package/es/components/DateTimeDiffFormat.js +185 -209
  11. package/es/components/FormatText.js +7 -27
  12. package/es/components/HOCI18N.js +35 -58
  13. package/es/components/I18N.js +48 -74
  14. package/es/components/I18NProvider.js +59 -93
  15. package/es/components/PluralFormat.js +28 -51
  16. package/es/components/UserTimeDiffFormat.js +66 -81
  17. package/es/components/__tests__/DateTimeDiffFormat.spec.js +810 -663
  18. package/es/components/__tests__/FormatText.spec.js +22 -19
  19. package/es/components/__tests__/HOCI18N.spec.js +19 -25
  20. package/es/components/__tests__/I18N.spec.js +23 -21
  21. package/es/components/__tests__/I18NProvider.spec.js +38 -47
  22. package/es/components/__tests__/PluralFormat.spec.js +23 -20
  23. package/es/components/__tests__/UserTimeDiffFormat.spec.js +1259 -1110
  24. package/es/index.js +13 -15
  25. package/es/utils/__tests__/jsxTranslations.spec.js +170 -0
  26. package/es/utils/errorReporter.js +41 -0
  27. package/es/utils/index.js +543 -0
  28. package/es/utils/jsxTranslations.js +185 -0
  29. package/lib/I18NContext.js +5 -10
  30. package/lib/components/DateTimeDiffFormat.js +131 -146
  31. package/lib/components/FormatText.js +29 -42
  32. package/lib/components/HOCI18N.js +34 -45
  33. package/lib/components/I18N.js +46 -57
  34. package/lib/components/I18NProvider.js +72 -95
  35. package/lib/components/PluralFormat.js +39 -55
  36. package/lib/components/UserTimeDiffFormat.js +76 -84
  37. package/lib/components/__tests__/DateTimeDiffFormat.spec.js +751 -635
  38. package/lib/components/__tests__/FormatText.spec.js +21 -30
  39. package/lib/components/__tests__/HOCI18N.spec.js +22 -41
  40. package/lib/components/__tests__/I18N.spec.js +20 -33
  41. package/lib/components/__tests__/I18NProvider.spec.js +40 -63
  42. package/lib/components/__tests__/PluralFormat.spec.js +23 -35
  43. package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1195 -1046
  44. package/lib/index.js +83 -104
  45. package/lib/utils/__tests__/jsxTranslations.spec.js +172 -0
  46. package/lib/utils/errorReporter.js +49 -0
  47. package/lib/utils/index.js +583 -0
  48. package/lib/utils/jsxTranslations.js +216 -0
  49. package/package.json +4 -3
  50. package/src/components/DateTimeDiffFormat.js +84 -55
  51. package/src/components/I18N.js +2 -0
  52. package/src/components/I18NProvider.js +44 -33
  53. package/src/components/UserTimeDiffFormat.js +22 -18
  54. package/src/index.js +12 -9
  55. package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
  56. package/src/utils/errorReporter.js +48 -0
  57. package/src/utils/index.js +644 -0
  58. package/src/utils/jsxTranslations.js +199 -0
  59. package/es/components/NewDateFormat.js +0 -50
  60. package/es/offset.js +0 -629
  61. package/es/timezones.js +0 -118
  62. package/es/utils.js +0 -621
  63. package/lib/components/NewDateFormat.js +0 -68
  64. package/lib/offset.js +0 -634
  65. package/lib/timezones.js +0 -129
  66. package/lib/utils.js +0 -651
  67. package/src/components/NewDateFormat.js +0 -60
  68. package/src/offset.js +0 -629
  69. package/src/timezones.js +0 -113
  70. package/src/utils.js +0 -648
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createElement = createElement;
8
+ exports.generateChildren = generateChildren;
9
+ exports.getI18NComponent = getI18NComponent;
10
+ exports.placeComponentForTags = placeComponentForTags;
11
+ exports.prepareI18NFunc = prepareI18NFunc;
12
+ exports.replaceWithComponentPlaceHolder = replaceWithComponentPlaceHolder;
13
+ exports.splitMatchedExp = splitMatchedExp;
14
+ var _react = _interopRequireDefault(require("react"));
15
+ var _index = require("./index");
16
+ var _I18NProvider = require("../components/I18NProvider");
17
+ var _errorReporter = require("./errorReporter");
18
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
19
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
20
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
21
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
22
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
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
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
25
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
26
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
27
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
28
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
29
+ function splitMatchedExp(_ref) {
30
+ var expression = _ref.expression,
31
+ charLenToOmit = _ref.charLenToOmit,
32
+ string = _ref.string;
33
+ var splitString = string.split(new RegExp(expression, 'g'));
34
+ var matchedExpAll = string.matchAll(new RegExp(expression, 'g'));
35
+ var matchedExpKeys = [];
36
+ var _iterator = _createForOfIteratorHelper(matchedExpAll),
37
+ _step;
38
+ try {
39
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
40
+ var match = _step.value;
41
+ var value = match[0];
42
+ matchedExpKeys.push(value.substring(charLenToOmit, value.length - charLenToOmit));
43
+ }
44
+ } catch (err) {
45
+ _iterator.e(err);
46
+ } finally {
47
+ _iterator.f();
48
+ }
49
+ return {
50
+ splitString: splitString,
51
+ matchedExpKeys: matchedExpKeys
52
+ };
53
+ }
54
+ function generateChildren(_ref2) {
55
+ var children = _ref2.children,
56
+ child = _ref2.child;
57
+ var newChildren = [],
58
+ stringPlaceHolders = {};
59
+ var handleString = function handleString(string) {
60
+ if (string) {
61
+ var _splitMatchedExp = splitMatchedExp({
62
+ expression: '{[0-9]+?}',
63
+ charLenToOmit: 1,
64
+ string: string
65
+ }),
66
+ splitString = _splitMatchedExp.splitString,
67
+ matchedExpKeys = _splitMatchedExp.matchedExpKeys;
68
+ stringPlaceHolders[newChildren.length] = matchedExpKeys;
69
+ newChildren.push(splitString);
70
+ }
71
+ };
72
+ var _splitMatchedExp2 = splitMatchedExp({
73
+ expression: '<[A-Za-z0-9]+?>',
74
+ charLenToOmit: 1,
75
+ string: child
76
+ }),
77
+ splitChild = _splitMatchedExp2.splitString,
78
+ childrenKeys = _splitMatchedExp2.matchedExpKeys;
79
+ childrenKeys.forEach(function (childKey, childIndex) {
80
+ var matchedChild = splitChild[childIndex];
81
+ handleString(matchedChild);
82
+ newChildren.push(children[childKey]);
83
+ });
84
+ handleString(splitChild[childrenKeys.length]);
85
+ return {
86
+ newChildren: newChildren,
87
+ stringPlaceHolders: stringPlaceHolders
88
+ };
89
+ }
90
+ function createElement() {
91
+ var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
92
+ componentId = _ref3.componentId,
93
+ _ref3$children = _ref3.children,
94
+ children = _ref3$children === void 0 ? [] : _ref3$children,
95
+ _ref3$stringPlaceHold = _ref3.stringPlaceHolders,
96
+ stringPlaceHolders = _ref3$stringPlaceHold === void 0 ? {} : _ref3$stringPlaceHold;
97
+ return function () {
98
+ var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
99
+ _ref4$components = _ref4.components,
100
+ components = _ref4$components === void 0 ? {} : _ref4$components,
101
+ _ref4$values = _ref4.values,
102
+ values = _ref4$values === void 0 ? [] : _ref4$values;
103
+ var _ref5 = components[componentId] || {},
104
+ _ref5$type = _ref5.type,
105
+ type = _ref5$type === void 0 ? _react["default"].Fragment : _ref5$type,
106
+ props = _ref5.props;
107
+ var childElements = children.map(function (child, index) {
108
+ if (typeof child === 'function') {
109
+ return child({
110
+ components: components,
111
+ values: values
112
+ });
113
+ }
114
+ var string = '',
115
+ stringIndex = 0;
116
+ (stringPlaceHolders[index] || []).map(function (stringId, index) {
117
+ if (child[index]) {
118
+ string += child[index];
119
+ }
120
+ string += values[stringId];
121
+ stringIndex++;
122
+ });
123
+ if (child[stringIndex]) {
124
+ string += child[stringIndex];
125
+ }
126
+ return string;
127
+ });
128
+ return /*#__PURE__*/_react["default"].createElement.apply(_react["default"], [type, props].concat(_toConsumableArray(childElements)));
129
+ };
130
+ }
131
+ ;
132
+ function replaceWithComponentPlaceHolder(_ref6) {
133
+ var componentId = _ref6.componentId,
134
+ i18nKey = _ref6.i18nKey,
135
+ childrenLength = _ref6.childrenLength;
136
+ var closingTagIndex = i18nKey.indexOf("</".concat(componentId, ">"));
137
+ var childWithOpenTag = i18nKey.substring(0, closingTagIndex);
138
+ var openTagIndex = childWithOpenTag.lastIndexOf("<".concat(componentId, ">"));
139
+ return i18nKey.substring(0, openTagIndex) + "<0".concat(childrenLength).concat(componentId, ">") + i18nKey.substring(closingTagIndex + "".concat(componentId).length + 3);
140
+ }
141
+ function prepareI18NFunc() {
142
+ var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
143
+ i18nKey = _ref7.i18nKey,
144
+ _ref7$children = _ref7.children,
145
+ children = _ref7$children === void 0 ? {} : _ref7$children;
146
+ var componentIdMatch = i18nKey.match(/<\/[A-Za-z0-9]+?>/);
147
+ if (componentIdMatch) {
148
+ var componentId = componentIdMatch[0].substring(2, componentIdMatch[0].length - 1);
149
+ var childWithOpenTag = (i18nKey.match(new RegExp("(.*?)(?=</".concat(componentId, ">)"))) || [])[0] || '';
150
+ var child = childWithOpenTag.split("<".concat(componentId, ">")).pop();
151
+ var _generateChildren = generateChildren({
152
+ children: children,
153
+ child: child
154
+ }),
155
+ _newChildren = _generateChildren.newChildren,
156
+ _stringPlaceHolders = _generateChildren.stringPlaceHolders;
157
+ var childrenLength = Object.keys(children).length;
158
+ children["0".concat(childrenLength).concat(componentId)] = createElement({
159
+ componentId: componentId,
160
+ children: _newChildren,
161
+ stringPlaceHolders: _stringPlaceHolders
162
+ });
163
+ i18nKey = replaceWithComponentPlaceHolder({
164
+ componentId: componentId,
165
+ i18nKey: i18nKey,
166
+ childrenLength: childrenLength
167
+ });
168
+ return prepareI18NFunc({
169
+ i18nKey: i18nKey,
170
+ children: children
171
+ });
172
+ }
173
+ var _generateChildren2 = generateChildren({
174
+ child: i18nKey,
175
+ children: children
176
+ }),
177
+ newChildren = _generateChildren2.newChildren,
178
+ stringPlaceHolders = _generateChildren2.stringPlaceHolders;
179
+ return createElement({
180
+ componentId: -1,
181
+ children: newChildren,
182
+ stringPlaceHolders: stringPlaceHolders
183
+ });
184
+ }
185
+ function i18nMechanismForComponents(i18nValue, key) {
186
+ if (typeof i18nValue === 'string') {
187
+ i18nValue = (0, _index.unescapeUnicode)(i18nValue);
188
+ var value = prepareI18NFunc({
189
+ i18nKey: i18nValue
190
+ });
191
+ window.loadI18nChunk && window.loadI18nChunk(_defineProperty({}, key, value));
192
+ i18nValue = value;
193
+ }
194
+ return i18nValue;
195
+ }
196
+ function placeComponentForTags(i18nValue) {
197
+ var value = _I18NProvider.i18NProviderUtils.getI18NComponent(i18nValue);
198
+ return i18nMechanismForComponents(value, value);
199
+ }
200
+ function getI18NComponent(i18n) {
201
+ if (typeof i18n === 'undefined') {
202
+ (0, _errorReporter.reportI18NError)(_errorReporter.I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object_jsx');
203
+ return function (key) {
204
+ return key;
205
+ };
206
+ }
207
+ return function (key) {
208
+ var i18nStr = i18n[key];
209
+ if (i18nStr === undefined) {
210
+ var isNumeric = /^\d+$/.test(key);
211
+ (0, _errorReporter.reportI18NError)(isNumeric ? _errorReporter.I18N_ERROR_TYPES.NUMERIC_FALLBACK : _errorReporter.I18N_ERROR_TYPES.MISSING_KEY, key);
212
+ return (0, _errorReporter.getFallbackText)(key);
213
+ }
214
+ return i18nMechanismForComponents(i18nStr, key);
215
+ };
216
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/i18n",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.41-murphy",
4
4
  "main": "lib/index",
5
5
  "module": "es/index.js",
6
6
  "jsnext:main": "es/index.js",
@@ -12,14 +12,15 @@
12
12
  "clean": "react-cli clean lib es coverage",
13
13
  "build": "react-cli build:component:cmjs",
14
14
  "build:es": "react-cli build:library:es",
15
- "build:dev": "npm run clean && npm run build --module:mode=dev -- -w",
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": "5.0.0-rc2.1"
23
+ "@zoho/SecurityJS": "7.2.4"
23
24
  },
24
25
  "react-cli": {
25
26
  "docs": {
@@ -6,9 +6,10 @@ import {
6
6
  getDiffObj,
7
7
  formatDate,
8
8
  getLyears,
9
- convertUtcToUserTz
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);
@@ -31,6 +32,7 @@ export default class DateTimeDiffFormat extends React.Component {
31
32
  const {
32
33
  type,
33
34
  page,
35
+ isNeedTime,
34
36
  from,
35
37
  fromTzData,
36
38
  to,
@@ -43,11 +45,19 @@ export default class DateTimeDiffFormat extends React.Component {
43
45
  dataId,
44
46
  className = null,
45
47
  title = null,
46
- isOverdue
48
+ isOverdue,
49
+ timeFormat,
50
+ datePattern,
51
+ isEnabledCurrentYear,
52
+ isDateField
47
53
  } = this.props;
48
54
 
49
- let fromDateObj = convertUtcToUserTz(from, fromTzData).getTime();
50
- let toDateObj = convertUtcToUserTz(to, toTzData).getTime();
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();
51
61
 
52
62
  let diffMin = new Date(to).getTime() - new Date(from).getTime();
53
63
  let suffix = this.getSuffix(diffMin);
@@ -66,17 +76,18 @@ export default class DateTimeDiffFormat extends React.Component {
66
76
  days: diff.yd,
67
77
  yDays: pad(diff.yd, 2),
68
78
  isWithInAWeek: withInAWeak,
69
- suffix: suffix
79
+ suffix: suffix,
70
80
  };
71
81
  let diffObj1 = {
82
+ to: to,
72
83
  type: type,
73
84
  page: page,
85
+ isNeedTime: isNeedTime,
74
86
  hours: diff.h,
75
87
  minutes: diff.m,
76
88
  seconds: diff.s,
77
89
  years: diff.y,
78
90
  yDays: diff.yd,
79
- yMonth: diff.m,
80
91
  isWithInAWeek: withInAWeak,
81
92
  suffix: suffix,
82
93
  crntDate: new Date(from).getDate(),
@@ -92,9 +103,27 @@ export default class DateTimeDiffFormat extends React.Component {
92
103
  tMinutes: new Date(to).getMinutes(),
93
104
  tSeconds: new Date(to).getSeconds(),
94
105
  betweenleepYears: getLyears(from, to),
95
- isOverdue: isOverdue
106
+ isOverdue: isOverdue,
107
+ timeFormat: timeFormat,
108
+ datePattern: datePattern,
109
+ dateTimePattern: `${datePattern} ${timeFormat}`,
96
110
  };
97
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
+
98
127
  let key = '';
99
128
  let values = [];
100
129
  let text = null;
@@ -134,57 +163,56 @@ export default class DateTimeDiffFormat extends React.Component {
134
163
  text = formatDate(toDateObj, value, diffObj1);
135
164
  }
136
165
  } else {
137
- if (diff.y === 0 && (diff.yd === 0 || diff.yd === 1)) {
138
- let dateObj = new Date(toDateObj);
139
- let curDateObj = new Date(fromDateObj);
140
- if (dateObj.getDate() === curDateObj.getDate()) {
141
- if (typeof today === 'function') {
142
- var value = today(diffObj1);
143
- key = value.key;
144
- values = getValues(value.params, diffObj);
145
- } else if (typeof today === 'object') {
146
- key = today.key;
147
- values = getValues(today.params, diffObj);
148
- isSuffixEnable = true;
149
- } else if (typeof today === 'string') {
150
- text = formatDate(toDateObj, today);
151
- }
152
- } else if (dateObj.getDate() < curDateObj.getDate()) {
153
- if (typeof yesterday === 'function') {
154
- var value = yesterday(diffObj1);
155
- key = value.key;
156
- values = getValues(value.params, diffObj);
157
- } else if (typeof yesterday === 'object') {
158
- key = yesterday.key;
159
- values = getValues(yesterday.params, diffObj);
160
- } else if (typeof yesterday === 'string') {
161
- text = formatDate(toDateObj, yesterday);
162
- }
163
- } else if (dateObj.getDate() > curDateObj.getDate()) {
164
- if (typeof tomorrow === 'function') {
165
- var value = tomorrow(diffObj1);
166
- key = value.key;
167
- text = getValues(value.params, diffObj);
168
- } else if (typeof tomorrow === 'object') {
169
- key = tomorrow.key;
170
- values = getValues(tomorrow.params, diffObj);
171
- } else if (typeof tomorrow === 'string') {
172
- 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
+ }
173
191
  }
174
192
  }
175
- } else {
176
- var value = others(diffObj1);
177
- if (typeof value === 'object') {
178
- key = value.key;
179
- values = getValues(value.params, diffObj);
180
- isSuffixEnable = true;
181
- } else if (typeof value === 'string') {
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);
182
207
  text = formatDate(toDateObj, value);
183
208
  }
209
+ } else {
210
+ var value = others(diffObj1);
211
+ text = formatDate(toDateObj, value);
184
212
  }
185
213
  }
186
214
  return text ? (
187
- <span className={className} data-title={title} data-id={dataId}>
215
+ <span className={className} data-title={title} data-id={dataId} data-test-id={dataId}>
188
216
  {text}
189
217
  </span>
190
218
  ) : (
@@ -204,6 +232,7 @@ DateTimeDiffFormat.propTypes = {
204
232
  format: PropTypes.func,
205
233
  from: PropTypes.string,
206
234
  fromTzData: PropTypes.object,
235
+ isDateField: PropTypes.bool,
207
236
  later: PropTypes.string,
208
237
  others: PropTypes.func,
209
238
  title: PropTypes.string,
@@ -212,16 +241,16 @@ DateTimeDiffFormat.propTypes = {
212
241
  today: PropTypes.oneOfType([
213
242
  PropTypes.string,
214
243
  PropTypes.object,
215
- PropTypes.func
244
+ PropTypes.func,
216
245
  ]),
217
246
  tomorrow: PropTypes.oneOfType([
218
247
  PropTypes.string,
219
248
  PropTypes.object,
220
- PropTypes.func
249
+ PropTypes.func,
221
250
  ]),
222
251
  yesterday: PropTypes.oneOfType([
223
252
  PropTypes.string,
224
253
  PropTypes.object,
225
- PropTypes.func
226
- ])
254
+ PropTypes.func,
255
+ ]),
227
256
  };
@@ -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 { unpack } from '../timezones';
5
- import { createSelector } from 'reselect';
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
- const getTzData = createSelector(
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.userDateFormat = userDateFormat(
24
- i18NProviderUtils.getI18NValue,
25
- unpack(props.tzData)
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(next) {
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 !== next.i18n ||
42
- timeZone !== next.timeZone ||
43
- datePattern !== next.datePattern ||
44
- timeFormat !== next.timeFormat ||
45
- dateTimeFormat !== next.dateTimeFormat ||
46
- direction !== next.direction ||
47
- tzData !== next.tzData
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(nextProps.i18n);
55
- i18NProviderUtils.userDateFormat = userDateFormat(
56
- i18NProviderUtils.getI18NValue,
57
- unpack(tzData)
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
- dateTimeFormat: this.props.dateTimeFormat
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
- dateTimeFormat: '',
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
- dateTimeFormat: PropTypes.string,
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.string
107
- };
117
+ tzData: PropTypes.object,
118
+ };