@zohodesk/i18n 1.0.0-exp.3 → 1.0.0-exp.5

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 (80) hide show
  1. package/README.md +139 -25
  2. package/es/components/DateTimeDiffFormat.js +64 -51
  3. package/es/components/FormatText.js +3 -2
  4. package/es/components/HOCI18N.js +38 -35
  5. package/es/components/I18N.js +4 -3
  6. package/es/components/I18NProvider.js +24 -13
  7. package/es/components/PluralFormat.js +3 -5
  8. package/es/components/UserTimeDiffFormat.js +19 -8
  9. package/es/components/__tests__/DateTimeDiffFormat.spec.js +179 -138
  10. package/es/components/__tests__/FormatText.spec.js +2 -3
  11. package/es/components/__tests__/HOCI18N.spec.js +2 -3
  12. package/es/components/__tests__/I18N.spec.js +6 -9
  13. package/es/components/__tests__/I18NProvider.spec.js +2 -3
  14. package/es/components/__tests__/PluralFormat.spec.js +3 -4
  15. package/es/components/__tests__/UserTimeDiffFormat.spec.js +289 -208
  16. package/es/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
  17. package/es/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
  18. package/es/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
  19. package/es/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
  20. package/es/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
  21. package/es/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
  22. package/es/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
  23. package/es/index.js +12 -12
  24. package/es/utils/__tests__/jsxTranslations.spec.js +174 -0
  25. package/es/utils/errorReporter.js +36 -0
  26. package/es/{utils.js → utils/index.js} +254 -217
  27. package/es/utils/jsxTranslations.js +201 -0
  28. package/lib/components/DateTimeDiffFormat.js +69 -56
  29. package/lib/components/FormatText.js +7 -7
  30. package/lib/components/HOCI18N.js +10 -10
  31. package/lib/components/I18N.js +11 -9
  32. package/lib/components/I18NProvider.js +32 -19
  33. package/lib/components/PluralFormat.js +8 -8
  34. package/lib/components/UserTimeDiffFormat.js +23 -16
  35. package/lib/components/__tests__/I18N.spec.js +1 -1
  36. package/lib/components/__tests__/I18NProvider.spec.js +3 -3
  37. package/lib/components/__tests__/UserTimeDiffFormat.spec.js +3 -3
  38. package/lib/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
  39. package/lib/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
  40. package/lib/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
  41. package/lib/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
  42. package/lib/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
  43. package/lib/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
  44. package/lib/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
  45. package/lib/index.js +83 -53
  46. package/lib/utils/__tests__/jsxTranslations.spec.js +183 -0
  47. package/lib/utils/errorReporter.js +47 -0
  48. package/lib/{utils.js → utils/index.js} +281 -267
  49. package/lib/utils/jsxTranslations.js +252 -0
  50. package/package.json +30 -29
  51. package/src/I18NContext.js +2 -2
  52. package/src/components/DateTimeDiffFormat.js +256 -229
  53. package/src/components/FormatText.js +14 -14
  54. package/src/components/HOCI18N.js +37 -37
  55. package/src/components/I18N.js +74 -72
  56. package/src/components/I18NProvider.js +118 -102
  57. package/src/components/PluralFormat.js +37 -37
  58. package/src/components/UserTimeDiffFormat.js +97 -93
  59. package/src/components/__tests__/DateTimeDiffFormat.spec.js +618 -618
  60. package/src/components/__tests__/FormatText.spec.js +26 -26
  61. package/src/components/__tests__/HOCI18N.spec.js +33 -33
  62. package/src/components/__tests__/I18N.spec.js +29 -29
  63. package/src/components/__tests__/I18NProvider.spec.js +65 -65
  64. package/src/components/__tests__/PluralFormat.spec.js +27 -27
  65. package/src/components/__tests__/UserTimeDiffFormat.spec.js +1076 -1076
  66. package/src/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
  67. package/src/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
  68. package/src/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
  69. package/src/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
  70. package/src/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
  71. package/src/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
  72. package/src/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
  73. package/src/index.js +38 -33
  74. package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
  75. package/src/utils/errorReporter.js +39 -0
  76. package/src/{utils.js → utils/index.js} +636 -595
  77. package/src/utils/jsxTranslations.js +191 -0
  78. package/es/components/NewDateFormat.js +0 -54
  79. package/lib/components/NewDateFormat.js +0 -60
  80. package/src/components/NewDateFormat.js +0 -60
package/README.md CHANGED
@@ -1,25 +1,139 @@
1
- # i18n
2
-
3
- # 1.0.0-beta.7
4
-
5
- - 'userDateFormat' util method - 'others' function fix
6
-
7
- # 1.0.0-beta.6
8
-
9
- - Added new prop 'isNeedTime' for DateTimeDiffFormat Component
10
-
11
- # 1.0.0-beta.5
12
-
13
- - Timezone logic moved to @zohodesk/datetimejs
14
-
15
- # 1.0.0-beta.4
16
-
17
- - Added new prop 'page' for DateTimeDiffFormat Component
18
-
19
- # 1.0.0-beta.3
20
-
21
- - Added support for exact times along with relative times in format() function
22
-
23
- # 1.0.0-beta.0
24
-
25
- - Test Publish
1
+ # i18n
2
+
3
+ # 1.0.0-beta.34
4
+
5
+ - Tagholder Replacement with React Component
6
+
7
+ # 1.0.0-beta.33
8
+
9
+ - Upgrading @zoho/SecurityJS package to 7.2.4
10
+
11
+ # 1.0.0-beta.32
12
+
13
+ - Upgrading @zoho/SecurityJS package to 7.2.0
14
+
15
+ # 1.0.0-beta.31
16
+
17
+ - Syntax correction in Update Flow
18
+
19
+ # 1.0.0-beta.30
20
+
21
+ - Upgrading @zoho/SecurityJS package to 6.4.2
22
+
23
+ # 1.0.0-beta.29
24
+
25
+ - Downgrading @zoho/SecurityJS package to 6.3.0
26
+
27
+
28
+ # 1.0.0-beta.28
29
+
30
+ - Updating @zoho/SecurityJS package to 7.0.2
31
+
32
+
33
+ # 1.0.0-beta.27
34
+
35
+ - JSX support within a text
36
+
37
+ # 1.0.0-beta.26
38
+
39
+ - Localization feature enhancement in i18n method.
40
+
41
+ # 1.0.0-beta.25
42
+
43
+ - July i18n key correction
44
+
45
+ # 1.0.0-beta.24
46
+
47
+ - I18N support for Days, Months and 12-hour time variables.
48
+
49
+ # 1.0.0-beta.23
50
+
51
+ - Zoho security version updated.
52
+
53
+ # 1.0.0-beta.22
54
+
55
+ - Data test id added for I18N.js
56
+
57
+ # 1.0.0-beta.21
58
+
59
+ - Data test id added for dateTimedifformat.js
60
+
61
+ # 1.0.0-beta.20
62
+
63
+ - Date field issue fixed in UserTimeDiffFormat component
64
+
65
+ # 1.0.0-beta.19
66
+
67
+ - In this version we have made changes in i18n provider to call user date format function only if the time zone data is available.
68
+
69
+ # 1.0.0-beta.18
70
+
71
+ - Localization feature added and incorporated into getI18NValue Method.
72
+
73
+ # 1.0.0-beta.17
74
+
75
+ - There was some i18n changes done in live before moving the date format build to live. Since we need these changes we have published it as new version.
76
+
77
+ # 1.0.0-beta.16
78
+
79
+ - DatePattern and dateTimePattern key has been changed for the date format build.
80
+
81
+ # 1.0.0-beta.15.1
82
+
83
+ - Zoho security version updated.
84
+
85
+ # 1.0.0-beta.15
86
+
87
+ - When working on date format build we have published I18n. Also, before moving date format build to master we had a emergency fix that need to be sent, so when publishing I18n we have published the date format changes with the next version.
88
+
89
+ # 1.0.0-beta.14
90
+
91
+ - Issue fixed in enable current year.
92
+
93
+ # 1.0.0-beta.13
94
+
95
+ - Issue fixed in due date.
96
+
97
+ # 1.0.0-beta.12
98
+
99
+ - Issue fixed in date Format Pattern.
100
+
101
+ # 1.0.0-beta.11
102
+
103
+ - Date Format Changes
104
+
105
+ # 1.0.0-beta.10
106
+
107
+ - Date Format Issue Fixes
108
+
109
+ # 1.0.0-beta.9
110
+
111
+ - Date Format Changes
112
+
113
+ # 1.0.0-beta.8
114
+
115
+ - ES Module Support Changes
116
+
117
+ # 1.0.0-beta.7
118
+
119
+ - 'userDateFormat' util method - 'others' function fix
120
+
121
+ # 1.0.0-beta.6
122
+
123
+ - Added new prop 'isNeedTime' for DateTimeDiffFormat Component
124
+
125
+ # 1.0.0-beta.5
126
+
127
+ - Timezone logic moved to @zohodesk/datetimejs
128
+
129
+ # 1.0.0-beta.4
130
+
131
+ - Added new prop 'page' for DateTimeDiffFormat Component
132
+
133
+ # 1.0.0-beta.3
134
+
135
+ - Added support for exact times along with relative times in format() function
136
+
137
+ # 1.0.0-beta.0
138
+
139
+ - Test Publish
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { pad, getValues, getDiffObj, formatDate, getLyears } from '../utils';
4
- import FormatText from './FormatText';
3
+ import { pad, getValues, getDiffObj, formatDate, getLyears, getDatePatternWithoutYear } from "../utils";
4
+ import FormatText from "./FormatText";
5
5
  import datetime from '@zohodesk/datetimejs';
6
6
  export default class DateTimeDiffFormat extends React.Component {
7
7
  constructor(props) {
@@ -40,10 +40,14 @@ export default class DateTimeDiffFormat extends React.Component {
40
40
  dataId,
41
41
  className = null,
42
42
  title = null,
43
- isOverdue
43
+ isOverdue,
44
+ timeFormat,
45
+ datePattern,
46
+ isEnabledCurrentYear,
47
+ isDateField
44
48
  } = this.props;
45
49
  let fromDateObj = datetime.toDate(datetime.tz.utcToTz(from, fromTzData)).getTime();
46
- let toDateObj = datetime.toDate(datetime.tz.utcToTz(to, toTzData)).getTime();
50
+ let toDateObj = datetime.toDate(isDateField ? to : datetime.tz.utcToTz(to, toTzData)).getTime();
47
51
  let diffMin = new Date(to).getTime() - new Date(from).getTime();
48
52
  let suffix = this.getSuffix(diffMin);
49
53
  let diff = getDiffObj(diffMin);
@@ -63,6 +67,7 @@ export default class DateTimeDiffFormat extends React.Component {
63
67
  suffix: suffix
64
68
  };
65
69
  let diffObj1 = {
70
+ to: to,
66
71
  type: type,
67
72
  page: page,
68
73
  isNeedTime: isNeedTime,
@@ -71,7 +76,6 @@ export default class DateTimeDiffFormat extends React.Component {
71
76
  seconds: diff.s,
72
77
  years: diff.y,
73
78
  yDays: diff.yd,
74
- yMonth: diff.m,
75
79
  isWithInAWeek: withInAWeak,
76
80
  suffix: suffix,
77
81
  crntDate: new Date(from).getDate(),
@@ -87,8 +91,22 @@ export default class DateTimeDiffFormat extends React.Component {
87
91
  tMinutes: new Date(to).getMinutes(),
88
92
  tSeconds: new Date(to).getSeconds(),
89
93
  betweenleepYears: getLyears(from, to),
90
- isOverdue: isOverdue
91
- };
94
+ isOverdue: isOverdue,
95
+ timeFormat: timeFormat,
96
+ datePattern: datePattern,
97
+ dateTimePattern: `${datePattern} ${timeFormat}`
98
+ }; //In if condition we'll remove year and set date format if the current year is not required
99
+ //In else part we'll set the date format as it is
100
+
101
+ if (isEnabledCurrentYear === true && diffObj1.years === 0 && diffObj1.tYear === diffObj1.crntYear) {
102
+ let dateFormat = getDatePatternWithoutYear(datePattern);
103
+ diffObj1.dateFormat = dateFormat;
104
+ diffObj1.dateTimeFormat = `${dateFormat} ${timeFormat}`;
105
+ } else {
106
+ diffObj1.dateFormat = datePattern;
107
+ diffObj1.dateTimeFormat = `${datePattern} ${timeFormat}`;
108
+ }
109
+
92
110
  let key = '';
93
111
  let values = [];
94
112
  let text = null;
@@ -129,62 +147,56 @@ export default class DateTimeDiffFormat extends React.Component {
129
147
  text = formatDate(toDateObj, value, diffObj1);
130
148
  }
131
149
  } else {
132
- if (diff.y === 0 && (diff.yd === 0 || diff.yd === 1)) {
133
- let dateObj = new Date(toDateObj);
134
- let curDateObj = new Date(fromDateObj);
150
+ let dateObj = new Date(toDateObj);
151
+ let curDateObj = new Date(fromDateObj);
152
+ let diffDayType = diffObj1.yDays; //In this condition, to calculate different days we have copied it from live --> diffDayType
135
153
 
136
- if (dateObj.getDate() === curDateObj.getDate()) {
137
- if (typeof today === 'function') {
138
- var value = today(diffObj1);
139
- key = value.key;
140
- values = getValues(value.params, diffObj);
141
- } else if (typeof today === 'object') {
142
- key = today.key;
143
- values = getValues(today.params, diffObj);
144
- isSuffixEnable = true;
145
- } else if (typeof today === 'string') {
146
- text = formatDate(toDateObj, today);
147
- }
148
- } else if (dateObj.getDate() < curDateObj.getDate()) {
149
- if (typeof yesterday === 'function') {
150
- var value = yesterday(diffObj1);
151
- key = value.key;
152
- values = getValues(value.params, diffObj);
153
- } else if (typeof yesterday === 'object') {
154
- key = yesterday.key;
155
- values = getValues(yesterday.params, diffObj);
156
- } else if (typeof yesterday === 'string') {
157
- text = formatDate(toDateObj, yesterday);
158
- }
159
- } else if (dateObj.getDate() > curDateObj.getDate()) {
160
- if (typeof tomorrow === 'function') {
161
- var value = tomorrow(diffObj1);
162
- key = value.key;
163
- text = getValues(value.params, diffObj);
164
- } else if (typeof tomorrow === 'object') {
165
- key = tomorrow.key;
166
- values = getValues(tomorrow.params, diffObj);
167
- } else if (typeof tomorrow === 'string') {
168
- text = formatDate(toDateObj, tomorrow);
154
+ if (isOverdue && dateObj.getDate() < curDateObj.getDate() && diffObj1.yDays == 0) {
155
+ diffDayType = -1;
156
+ }
157
+
158
+ if (!isOverdue) {
159
+ let diffHr = dateObj.getHours() - curDateObj.getHours();
160
+
161
+ if (diffHr < 0) {
162
+ diffDayType += 1;
163
+ } else if (diffHr == 0) {
164
+ let diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
165
+
166
+ if (diffMins < 0) {
167
+ diffDayType += 1;
168
+ } else if (diffMins == 0) {
169
+ let diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
170
+
171
+ if (diffSec < 0) {
172
+ diffDayType += 1;
173
+ }
169
174
  }
170
175
  }
171
- } else {
172
- var value = others(diffObj1);
176
+ }
173
177
 
174
- if (typeof value === 'object') {
175
- key = value.key;
176
- values = getValues(value.params, diffObj);
177
- isSuffixEnable = true;
178
- } else if (typeof value === 'string') {
178
+ if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
179
+ if (dateObj.getDate() === curDateObj.getDate()) {
180
+ var value = today && today(diffObj1) || others(diffObj1);
181
+ text = formatDate(toDateObj, value);
182
+ } else if (dateObj.getMonth() === curDateObj.getMonth() && dateObj.getDate() < curDateObj.getDate() || dateObj.getMonth() < curDateObj.getMonth()) {
183
+ var value = yesterday && yesterday(diffObj1) || others(diffObj1);
184
+ text = formatDate(toDateObj, value);
185
+ } else if (!isOverdue && diff.y === 0 && diffDayType === 1) {
186
+ var value = tomorrow && tomorrow(diffObj1) || others(diffObj1);
179
187
  text = formatDate(toDateObj, value);
180
188
  }
189
+ } else {
190
+ var value = others(diffObj1);
191
+ text = formatDate(toDateObj, value);
181
192
  }
182
193
  }
183
194
 
184
195
  return text ? /*#__PURE__*/React.createElement("span", {
185
196
  className: className,
186
197
  "data-title": title,
187
- "data-id": dataId
198
+ "data-id": dataId,
199
+ "data-test-id": dataId
188
200
  }, text) : /*#__PURE__*/React.createElement(FormatText, {
189
201
  i18NKey: isSuffixEnable && suffix !== '' ? `${key}.${suffix}` : key,
190
202
  values: values,
@@ -201,6 +213,7 @@ DateTimeDiffFormat.propTypes = {
201
213
  format: PropTypes.func,
202
214
  from: PropTypes.string,
203
215
  fromTzData: PropTypes.object,
216
+ isDateField: PropTypes.bool,
204
217
  later: PropTypes.string,
205
218
  others: PropTypes.func,
206
219
  title: PropTypes.string,
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import I18N from './I18N';
3
+ import I18N from "./I18N";
4
4
  export default class FormatText extends React.Component {
5
5
  render() {
6
- return /*#__PURE__*/React.createElement(I18N, this.props);
6
+ return /*#__PURE__*/React.createElement(I18N, { ...this.props
7
+ });
7
8
  }
8
9
 
9
10
  }
@@ -1,47 +1,50 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
1
  import React, { Children } from 'react';
4
2
  import PropTypes from 'prop-types';
5
- import { replaceI18NValuesWithRegex, unescapeUnicode } from '../utils';
6
- import { I18NContext } from '../I18NContext';
7
- export default ((i18NKeys = []) => Component => {
8
- class HOCI18N extends React.Component {
9
- constructor(props) {
10
- super(props);
11
- this.getI18NValue = this.getI18NValue.bind(this);
12
- }
13
-
14
- getI18NValue(key) {
15
- const {
16
- i18n
17
- } = this.context || {};
18
-
19
- if (typeof i18n === 'undefined') {
20
- return key;
3
+ import { replaceI18NValuesWithRegex, unescapeUnicode } from "../utils";
4
+ import { I18NContext } from "../I18NContext";
5
+ export default (function () {
6
+ let i18NKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
7
+ return Component => {
8
+ class HOCI18N extends React.Component {
9
+ constructor(props) {
10
+ super(props);
11
+ this.getI18NValue = this.getI18NValue.bind(this);
21
12
  }
22
13
 
23
- let i18nStr = i18n[key];
14
+ getI18NValue(key) {
15
+ const {
16
+ i18n
17
+ } = this.context || {};
24
18
 
25
- if (i18nStr === undefined) {
26
- return key;
27
- }
19
+ if (typeof i18n === 'undefined') {
20
+ return key;
21
+ }
28
22
 
29
- return unescapeUnicode(i18nStr);
30
- }
23
+ let i18nStr = i18n[key];
31
24
 
32
- render() {
33
- let i18nProps = i18NKeys.reduce((result, key) => {
34
- if (this.props[key]) {
35
- result[key] = this.getI18NValue(this.props[key]);
25
+ if (i18nStr === undefined) {
26
+ return key;
36
27
  }
37
28
 
38
- return result;
39
- }, {});
40
- return /*#__PURE__*/React.createElement(Component, _extends({}, this.props, i18nProps));
41
- }
29
+ return unescapeUnicode(i18nStr);
30
+ }
42
31
 
43
- }
32
+ render() {
33
+ let i18nProps = i18NKeys.reduce((result, key) => {
34
+ if (this.props[key]) {
35
+ result[key] = this.getI18NValue(this.props[key]);
36
+ }
37
+
38
+ return result;
39
+ }, {});
40
+ return /*#__PURE__*/React.createElement(Component, { ...this.props,
41
+ ...i18nProps
42
+ });
43
+ }
44
+
45
+ }
44
46
 
45
- HOCI18N.contextType = I18NContext;
46
- return HOCI18N;
47
+ HOCI18N.contextType = I18NContext;
48
+ return HOCI18N;
49
+ };
47
50
  });
@@ -1,9 +1,8 @@
1
- import "core-js/modules/web.dom-collections.iterator";
2
1
  import React, { Children } from 'react';
3
2
  import PropTypes from 'prop-types';
4
- import { replaceI18NValuesWithRegex, unescapeUnicode } from '../utils';
3
+ import { replaceI18NValuesWithRegex, unescapeUnicode } from "../utils";
5
4
  import { HTMLPurifier } from '@zoho/SecurityJS';
6
- import { I18NContext } from '../I18NContext';
5
+ import { I18NContext } from "../I18NContext";
7
6
  export default class I18N extends React.Component {
8
7
  constructor(props) {
9
8
  super(props);
@@ -45,6 +44,7 @@ export default class I18N extends React.Component {
45
44
 
46
45
  if (this.props.dataId) {
47
46
  props['data-id'] = this.props.dataId;
47
+ props['data-test-id'] = this.props.dataId;
48
48
  }
49
49
 
50
50
  if (this.props.isHtml) {
@@ -68,6 +68,7 @@ I18N.propTypes = {
68
68
  i18NKey: PropTypes.string.isRequired,
69
69
  isHtml: PropTypes.bool,
70
70
  tag: PropTypes.string,
71
+ dataId: PropTypes.string,
71
72
  values: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
72
73
  };
73
74
  I18N.defaultProps = {
@@ -1,41 +1,52 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { getI18NValue, userDateFormat } from '../utils';
4
- import { I18NContext } from '../I18NContext';
3
+ import { getI18NValue, userDateFormat } from "../utils";
4
+ import { getI18NComponent } from "../utils/jsxTranslations";
5
+ import { I18NContext } from "../I18NContext";
5
6
  const emptyObj = {};
6
7
 
7
8
  const dummy = (key, values) => key;
8
9
 
9
10
  export const i18NProviderUtils = {
10
11
  getI18NValue: dummy,
11
- userDateFormat: dummy
12
+ userDateFormat: dummy,
13
+ getI18NComponent: dummy
12
14
  };
13
15
  export default class I18NProvider extends React.Component {
14
16
  constructor(props, context) {
15
17
  super(props, context);
16
18
  i18NProviderUtils.getI18NValue = getI18NValue(props.i18n);
17
- i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, props.tzData);
19
+ i18NProviderUtils.getI18NComponent = getI18NComponent(props.i18n);
20
+
21
+ if (props.tzData) {
22
+ i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, props.tzData, props.timeFormat, props.datePattern, props.isEnabledCurrentYear);
23
+ }
18
24
  }
19
25
 
20
- componentDidUpdate(next) {
26
+ componentDidUpdate(prevProps) {
21
27
  let {
22
28
  i18n,
23
29
  timeZone,
24
30
  datePattern,
25
31
  timeFormat,
26
- dateTimeFormat,
27
32
  direction,
28
33
  onChange,
29
- tzData
34
+ tzData,
35
+ isEnabledCurrentYear
30
36
  } = this.props;
31
37
 
32
- if (i18n !== next.i18n || timeZone !== next.timeZone || datePattern !== next.datePattern || timeFormat !== next.timeFormat || dateTimeFormat !== next.dateTimeFormat || direction !== next.direction || tzData !== next.tzData) {
38
+ if (i18n !== prevProps.i18n || timeZone !== prevProps.timeZone || datePattern !== prevProps.datePattern || timeFormat !== prevProps.timeFormat || direction !== prevProps.direction || tzData !== prevProps.tzData || isEnabledCurrentYear !== prevProps.isEnabledCurrentYear) {
33
39
  this.promise = new Promise((res, rej) => {
34
40
  this.resolve = res;
35
41
  this.reject = rej;
36
42
  }).then(() => {
37
- i18NProviderUtils.getI18NValue = getI18NValue(nextProps.i18n);
38
- i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, props.tzData);
43
+ i18NProviderUtils.getI18NValue = getI18NValue(this.props.i18n);
44
+ i18NProviderUtils.getI18NComponent = getI18NComponent(this.props.i18n);
45
+
46
+ if (this.props.tzData) {
47
+ i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, this.props.tzData, this.props.timeFormat, this.props.datePattern, this.props.isEnabledCurrentYear);
48
+ }
49
+
39
50
  this.promise = null;
40
51
  }, () => {
41
52
  this.promise = null;
@@ -52,7 +63,7 @@ export default class I18NProvider extends React.Component {
52
63
  timeZone: this.props.timeZone,
53
64
  datePattern: this.props.datePattern,
54
65
  timeFormat: this.props.timeFormat,
55
- dateTimeFormat: this.props.dateTimeFormat,
66
+ isEnabledCurrentYear: this.props.isEnabledCurrentYear,
56
67
  tzData: this.props.tzData
57
68
  }
58
69
  }, this.props.children);
@@ -64,13 +75,13 @@ I18NProvider.defaultProps = {
64
75
  timeZone: '',
65
76
  datePattern: '',
66
77
  timeFormat: '',
67
- dateTimeFormat: '',
78
+ isEnabledCurrentYear: '',
68
79
  direction: 'ltr'
69
80
  };
70
81
  I18NProvider.propTypes = {
71
82
  children: PropTypes.element.isRequired,
72
83
  datePattern: PropTypes.string,
73
- dateTimeFormat: PropTypes.string,
84
+ isEnabledCurrentYear: PropTypes.string,
74
85
  direction: PropTypes.string,
75
86
  i18n: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
76
87
  onChange: PropTypes.func,
@@ -1,8 +1,6 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
1
  import React from 'react';
4
2
  import PropTypes from 'prop-types';
5
- import FormatText from './FormatText';
3
+ import FormatText from "./FormatText";
6
4
  export default class PluralFormat extends React.Component {
7
5
  render() {
8
6
  const {
@@ -23,13 +21,13 @@ export default class PluralFormat extends React.Component {
23
21
  }
24
22
 
25
23
  values = `${value}`;
26
- return /*#__PURE__*/React.createElement(FormatText, _extends({}, this.props, {
24
+ return /*#__PURE__*/React.createElement(FormatText, { ...this.props,
27
25
  i18NKey: key,
28
26
  values: values,
29
27
  one: null,
30
28
  many: null,
31
29
  zero: null
32
- }));
30
+ });
33
31
  }
34
32
 
35
33
  }
@@ -1,7 +1,7 @@
1
1
  import React, { Component } from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import DateTimeDiffFormat from './DateTimeDiffFormat';
4
- import { I18NContext } from '../I18NContext';
3
+ import DateTimeDiffFormat from "./DateTimeDiffFormat";
4
+ import { I18NContext } from "../I18NContext";
5
5
  export default class UserTimeDiffFormat extends Component {
6
6
  render() {
7
7
  let currentTime = new Date();
@@ -22,19 +22,25 @@ export default class UserTimeDiffFormat extends Component {
22
22
  className,
23
23
  displayType,
24
24
  dataId,
25
- isOverdue
25
+ isOverdue,
26
+ isDateField
26
27
  } = this.props;
27
28
  let {
28
29
  tzData,
29
30
  timeFormat,
30
31
  datePattern,
31
- dateTimeFormat
32
+ isEnabledCurrentYear
32
33
  } = this.context || {};
33
34
 
34
35
  if (!format && !others) {
35
- let pattern = displayType === 'date' ? datePattern : displayType === 'time' ? timeFormat : displayType === 'dateTime' ? dateTimeFormat : '';
36
-
37
- format = () => pattern;
36
+ format = _ref => {
37
+ let {
38
+ dateTimeFormat,
39
+ dateFormat,
40
+ timeFormat
41
+ } = _ref;
42
+ displayType === 'dateTime' ? dateTimeFormat : displayType === 'date' ? dateFormat : timeFormat;
43
+ };
38
44
  }
39
45
 
40
46
  return /*#__PURE__*/React.createElement(DateTimeDiffFormat, {
@@ -55,7 +61,11 @@ export default class UserTimeDiffFormat extends Component {
55
61
  title: title,
56
62
  className: className,
57
63
  dataId: dataId,
58
- isOverdue: isOverdue
64
+ isOverdue: isOverdue,
65
+ timeFormat: timeFormat,
66
+ datePattern: datePattern,
67
+ isEnabledCurrentYear: isEnabledCurrentYear,
68
+ isDateField: isDateField
59
69
  });
60
70
  }
61
71
 
@@ -66,6 +76,7 @@ UserTimeDiffFormat.propTypes = {
66
76
  dataId: PropTypes.string,
67
77
  displayType: PropTypes.oneOf(['date', 'time', 'dateTime']),
68
78
  format: PropTypes.func,
79
+ isDateField: PropTypes.bool,
69
80
  later: PropTypes.string,
70
81
  others: PropTypes.func,
71
82
  title: PropTypes.string,