@zohodesk/i18n 1.0.0-beta.15.1 → 1.0.0-beta.18

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 (67) hide show
  1. package/README.md +73 -41
  2. package/es/components/DateTimeDiffFormat.js +46 -12
  3. package/es/components/HOCI18N.js +33 -30
  4. package/es/components/I18NProvider.js +7 -16
  5. package/es/components/UserTimeDiffFormat.js +11 -9
  6. package/es/components/__tests__/DateTimeDiffFormat.spec.js +177 -136
  7. package/es/components/__tests__/FormatText.spec.js +0 -1
  8. package/es/components/__tests__/HOCI18N.spec.js +0 -1
  9. package/es/components/__tests__/I18N.spec.js +0 -2
  10. package/es/components/__tests__/I18NProvider.spec.js +0 -1
  11. package/es/components/__tests__/PluralFormat.spec.js +0 -1
  12. package/es/components/__tests__/UserTimeDiffFormat.spec.js +287 -206
  13. package/es/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
  14. package/es/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
  15. package/es/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
  16. package/es/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
  17. package/es/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
  18. package/es/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
  19. package/es/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
  20. package/es/index.js +2 -3
  21. package/es/utils.js +119 -171
  22. package/lib/components/DateTimeDiffFormat.js +49 -15
  23. package/lib/components/FormatText.js +4 -4
  24. package/lib/components/HOCI18N.js +4 -4
  25. package/lib/components/I18N.js +4 -4
  26. package/lib/components/I18NProvider.js +12 -21
  27. package/lib/components/PluralFormat.js +4 -4
  28. package/lib/components/UserTimeDiffFormat.js +12 -14
  29. package/lib/components/__tests__/I18NProvider.spec.js +1 -1
  30. package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1 -1
  31. package/lib/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
  32. package/lib/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
  33. package/lib/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
  34. package/lib/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
  35. package/lib/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
  36. package/lib/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
  37. package/lib/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
  38. package/lib/index.js +54 -56
  39. package/lib/utils.js +130 -212
  40. package/package.json +28 -28
  41. package/src/I18NContext.js +2 -2
  42. package/src/components/DateTimeDiffFormat.js +254 -211
  43. package/src/components/FormatText.js +14 -14
  44. package/src/components/HOCI18N.js +37 -37
  45. package/src/components/I18N.js +72 -72
  46. package/src/components/I18NProvider.js +106 -116
  47. package/src/components/PluralFormat.js +37 -37
  48. package/src/components/UserTimeDiffFormat.js +94 -103
  49. package/src/components/__tests__/DateTimeDiffFormat.spec.js +618 -618
  50. package/src/components/__tests__/FormatText.spec.js +26 -26
  51. package/src/components/__tests__/HOCI18N.spec.js +33 -33
  52. package/src/components/__tests__/I18N.spec.js +29 -29
  53. package/src/components/__tests__/I18NProvider.spec.js +65 -65
  54. package/src/components/__tests__/PluralFormat.spec.js +27 -27
  55. package/src/components/__tests__/UserTimeDiffFormat.spec.js +1076 -1076
  56. package/src/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
  57. package/src/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
  58. package/src/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
  59. package/src/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
  60. package/src/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
  61. package/src/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
  62. package/src/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
  63. package/src/index.js +33 -33
  64. package/src/utils.js +527 -587
  65. package/es/components/NewDateFormat.js +0 -53
  66. package/lib/components/NewDateFormat.js +0 -60
  67. package/src/components/NewDateFormat.js +0 -60
package/README.md CHANGED
@@ -1,41 +1,73 @@
1
- # i18n
2
-
3
- # 1.0.0-beta.15
4
-
5
- - 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.
6
-
7
- # 1.0.0-beta.10
8
-
9
- - Date Format Issue Fixes
10
-
11
- # 1.0.0-beta.9
12
-
13
- - Date Format Changes
14
-
15
- # 1.0.0-beta.8
16
-
17
- - ES Module Support Changes
18
-
19
- # 1.0.0-beta.7
20
-
21
- - 'userDateFormat' util method - 'others' function fix
22
-
23
- # 1.0.0-beta.6
24
-
25
- - Added new prop 'isNeedTime' for DateTimeDiffFormat Component
26
-
27
- # 1.0.0-beta.5
28
-
29
- - Timezone logic moved to @zohodesk/datetimejs
30
-
31
- # 1.0.0-beta.4
32
-
33
- - Added new prop 'page' for DateTimeDiffFormat Component
34
-
35
- # 1.0.0-beta.3
36
-
37
- - Added support for exact times along with relative times in format() function
38
-
39
- # 1.0.0-beta.0
40
-
41
- - Test Publish
1
+ # i18n
2
+
3
+ # 1.0.0-beta.18
4
+
5
+ - Localization feature added and incorporated into getI18NValue Method.
6
+
7
+ # 1.0.0-beta.17
8
+
9
+ - 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.
10
+
11
+ # 1.0.0-beta.16
12
+
13
+ - DatePattern and dateTimePattern key has been changed for the date format build.
14
+
15
+ # 1.0.0-beta.15.1
16
+
17
+ - Zoho security version updated.
18
+
19
+ # 1.0.0-beta.15
20
+
21
+ - 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.
22
+
23
+ # 1.0.0-beta.14
24
+
25
+ - Issue fixed in enable current year.
26
+
27
+ # 1.0.0-beta.13
28
+
29
+ - Issue fixed in due date.
30
+
31
+ # 1.0.0-beta.12
32
+
33
+ - Issue fixed in date Format Pattern.
34
+
35
+ # 1.0.0-beta.11
36
+
37
+ - Date Format Changes
38
+
39
+ # 1.0.0-beta.10
40
+
41
+ - Date Format Issue Fixes
42
+
43
+ # 1.0.0-beta.9
44
+
45
+ - Date Format Changes
46
+
47
+ # 1.0.0-beta.8
48
+
49
+ - ES Module Support Changes
50
+
51
+ # 1.0.0-beta.7
52
+
53
+ - 'userDateFormat' util method - 'others' function fix
54
+
55
+ # 1.0.0-beta.6
56
+
57
+ - Added new prop 'isNeedTime' for DateTimeDiffFormat Component
58
+
59
+ # 1.0.0-beta.5
60
+
61
+ - Timezone logic moved to @zohodesk/datetimejs
62
+
63
+ # 1.0.0-beta.4
64
+
65
+ - Added new prop 'page' for DateTimeDiffFormat Component
66
+
67
+ # 1.0.0-beta.3
68
+
69
+ - Added support for exact times along with relative times in format() function
70
+
71
+ # 1.0.0-beta.0
72
+
73
+ - Test Publish
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { pad, getValues, getDiffObj, formatDate, getLyears } from '../utils';
3
+ import { pad, getValues, getDiffObj, formatDate, getLyears, getDatePatternWithoutYear } from '../utils';
4
4
  import FormatText from './FormatText';
5
5
  import datetime from '@zohodesk/datetimejs';
6
6
  export default class DateTimeDiffFormat extends React.Component {
@@ -42,9 +42,8 @@ export default class DateTimeDiffFormat extends React.Component {
42
42
  title = null,
43
43
  isOverdue,
44
44
  timeFormat,
45
- dateTimeFormat,
46
- defaulDatePattern,
47
- defaultDateTimeFormat
45
+ datePattern,
46
+ isEnabledCurrentYear
48
47
  } = this.props;
49
48
  let fromDateObj = datetime.toDate(datetime.tz.utcToTz(from, fromTzData)).getTime();
50
49
  let toDateObj = datetime.toDate(datetime.tz.utcToTz(to, toTzData)).getTime();
@@ -76,7 +75,6 @@ export default class DateTimeDiffFormat extends React.Component {
76
75
  seconds: diff.s,
77
76
  years: diff.y,
78
77
  yDays: diff.yd,
79
- yMonth: diff.m,
80
78
  isWithInAWeek: withInAWeak,
81
79
  suffix: suffix,
82
80
  crntDate: new Date(from).getDate(),
@@ -94,9 +92,20 @@ export default class DateTimeDiffFormat extends React.Component {
94
92
  betweenleepYears: getLyears(from, to),
95
93
  isOverdue: isOverdue,
96
94
  timeFormat: timeFormat,
97
- datePattern: defaulDatePattern,
98
- dateTimeFormat: defaultDateTimeFormat
99
- };
95
+ datePattern: datePattern,
96
+ dateTimePattern: `${datePattern} ${timeFormat}`
97
+ }; //In if condition we'll remove year and set date format if the current year is not required
98
+ //In else part we'll set the date format as it is
99
+
100
+ if (isEnabledCurrentYear === true && diffObj1.years === 0 && diffObj1.tYear === diffObj1.crntYear) {
101
+ let dateFormat = getDatePatternWithoutYear(datePattern);
102
+ diffObj1.dateFormat = dateFormat;
103
+ diffObj1.dateTimeFormat = `${dateFormat} ${timeFormat}`;
104
+ } else {
105
+ diffObj1.dateFormat = datePattern;
106
+ diffObj1.dateTimeFormat = `${datePattern} ${timeFormat}`;
107
+ }
108
+
100
109
  let key = '';
101
110
  let values = [];
102
111
  let text = null;
@@ -137,17 +146,42 @@ export default class DateTimeDiffFormat extends React.Component {
137
146
  text = formatDate(toDateObj, value, diffObj1);
138
147
  }
139
148
  } else {
140
- if (diff.y === 0 && (diff.yd === 0 || diff.yd === 1)) {
141
- let dateObj = new Date(toDateObj);
142
- let curDateObj = new Date(fromDateObj);
149
+ let dateObj = new Date(toDateObj);
150
+ let curDateObj = new Date(fromDateObj);
151
+ let diffDayType = diffObj1.yDays; //In this condition, to calculate different days we have copied it from live --> diffDayType
152
+
153
+ if (isOverdue && dateObj.getDate() < curDateObj.getDate() && diffObj1.yDays == 0) {
154
+ diffDayType = -1;
155
+ }
156
+
157
+ if (!isOverdue) {
158
+ let diffHr = dateObj.getHours() - curDateObj.getHours();
159
+
160
+ if (diffHr < 0) {
161
+ diffDayType += 1;
162
+ } else if (diffHr == 0) {
163
+ let diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
164
+
165
+ if (diffMins < 0) {
166
+ diffDayType += 1;
167
+ } else if (diffMins == 0) {
168
+ let diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
169
+
170
+ if (diffSec < 0) {
171
+ diffDayType += 1;
172
+ }
173
+ }
174
+ }
175
+ }
143
176
 
177
+ if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
144
178
  if (dateObj.getDate() === curDateObj.getDate()) {
145
179
  var value = today && today(diffObj1) || others(diffObj1);
146
180
  text = formatDate(toDateObj, value);
147
181
  } else if (dateObj.getMonth() === curDateObj.getMonth() && dateObj.getDate() < curDateObj.getDate() || dateObj.getMonth() < curDateObj.getMonth()) {
148
182
  var value = yesterday && yesterday(diffObj1) || others(diffObj1);
149
183
  text = formatDate(toDateObj, value);
150
- } else if (dateObj.getMonth() > curDateObj.getMonth() || dateObj.getDate() > curDateObj.getDate()) {
184
+ } else if (!isOverdue && diff.y === 0 && diffDayType === 1) {
151
185
  var value = tomorrow && tomorrow(diffObj1) || others(diffObj1);
152
186
  text = formatDate(toDateObj, value);
153
187
  }
@@ -4,44 +4,47 @@ import React, { Children } from 'react';
4
4
  import PropTypes from 'prop-types';
5
5
  import { replaceI18NValuesWithRegex, unescapeUnicode } from '../utils';
6
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
- }
7
+ export default (function () {
8
+ let i18NKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
9
+ return Component => {
10
+ class HOCI18N extends React.Component {
11
+ constructor(props) {
12
+ super(props);
13
+ this.getI18NValue = this.getI18NValue.bind(this);
14
+ }
13
15
 
14
- getI18NValue(key) {
15
- const {
16
- i18n
17
- } = this.context || {};
16
+ getI18NValue(key) {
17
+ const {
18
+ i18n
19
+ } = this.context || {};
18
20
 
19
- if (typeof i18n === 'undefined') {
20
- return key;
21
- }
21
+ if (typeof i18n === 'undefined') {
22
+ return key;
23
+ }
24
+
25
+ let i18nStr = i18n[key];
22
26
 
23
- let i18nStr = i18n[key];
27
+ if (i18nStr === undefined) {
28
+ return key;
29
+ }
24
30
 
25
- if (i18nStr === undefined) {
26
- return key;
31
+ return unescapeUnicode(i18nStr);
27
32
  }
28
33
 
29
- return unescapeUnicode(i18nStr);
30
- }
34
+ render() {
35
+ let i18nProps = i18NKeys.reduce((result, key) => {
36
+ if (this.props[key]) {
37
+ result[key] = this.getI18NValue(this.props[key]);
38
+ }
31
39
 
32
- render() {
33
- let i18nProps = i18NKeys.reduce((result, key) => {
34
- if (this.props[key]) {
35
- result[key] = this.getI18NValue(this.props[key]);
36
- }
40
+ return result;
41
+ }, {});
42
+ return /*#__PURE__*/React.createElement(Component, _extends({}, this.props, i18nProps));
43
+ }
37
44
 
38
- return result;
39
- }, {});
40
- return /*#__PURE__*/React.createElement(Component, _extends({}, this.props, i18nProps));
41
45
  }
42
46
 
43
- }
44
-
45
- HOCI18N.contextType = I18NContext;
46
- return HOCI18N;
47
+ HOCI18N.contextType = I18NContext;
48
+ return HOCI18N;
49
+ };
47
50
  });
@@ -14,7 +14,7 @@ export default class I18NProvider extends React.Component {
14
14
  constructor(props, context) {
15
15
  super(props, context);
16
16
  i18NProviderUtils.getI18NValue = getI18NValue(props.i18n);
17
- i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, props.tzData, props.timeFormat, props.defaulDatePattern, props.defaultDateTimeFormat);
17
+ i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, props.tzData, props.timeFormat, props.datePattern, props.isEnabledCurrentYear);
18
18
  }
19
19
 
20
20
  componentDidUpdate(next) {
@@ -23,21 +23,18 @@ export default class I18NProvider extends React.Component {
23
23
  timeZone,
24
24
  datePattern,
25
25
  timeFormat,
26
- dateTimeFormat,
27
26
  direction,
28
27
  onChange,
29
- tzData,
30
- defaulDatePattern,
31
- defaultDateTimeFormat
28
+ tzData
32
29
  } = this.props;
33
30
 
34
- if (i18n !== next.i18n || timeZone !== next.timeZone || datePattern !== next.datePattern || timeFormat !== next.timeFormat || dateTimeFormat !== next.dateTimeFormat || direction !== next.direction || tzData !== next.tzData) {
31
+ if (i18n !== next.i18n || timeZone !== next.timeZone || datePattern !== next.datePattern || timeFormat !== next.timeFormat || direction !== next.direction || tzData !== next.tzData) {
35
32
  this.promise = new Promise((res, rej) => {
36
33
  this.resolve = res;
37
34
  this.reject = rej;
38
35
  }).then(() => {
39
36
  i18NProviderUtils.getI18NValue = getI18NValue(nextProps.i18n);
40
- i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, props.tzData, props.timeFormat, props.defaulDatePattern, props.defaultDateTimeFormat);
37
+ i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, props.tzData, props.timeFormat, props.datePattern, this.props.isEnabledCurrentYear);
41
38
  this.promise = null;
42
39
  }, () => {
43
40
  this.promise = null;
@@ -54,9 +51,7 @@ export default class I18NProvider extends React.Component {
54
51
  timeZone: this.props.timeZone,
55
52
  datePattern: this.props.datePattern,
56
53
  timeFormat: this.props.timeFormat,
57
- dateTimeFormat: this.props.dateTimeFormat,
58
- defaulDatePattern: this.props.defaulDatePattern,
59
- defaultDateTimeFormat: this.props.defaultDateTimeFormat,
54
+ isEnabledCurrentYear: this.props.isEnabledCurrentYear,
60
55
  tzData: this.props.tzData
61
56
  }
62
57
  }, this.props.children);
@@ -68,17 +63,13 @@ I18NProvider.defaultProps = {
68
63
  timeZone: '',
69
64
  datePattern: '',
70
65
  timeFormat: '',
71
- dateTimeFormat: '',
72
- defaulDatePattern: '',
73
- defaultDateTimeFormat: '',
66
+ isEnabledCurrentYear: '',
74
67
  direction: 'ltr'
75
68
  };
76
69
  I18NProvider.propTypes = {
77
70
  children: PropTypes.element.isRequired,
78
71
  datePattern: PropTypes.string,
79
- dateTimeFormat: PropTypes.string,
80
- defaulDatePattern: PropTypes.string,
81
- defaultDateTimeFormat: PropTypes.string,
72
+ isEnabledCurrentYear: PropTypes.string,
82
73
  direction: PropTypes.string,
83
74
  i18n: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
84
75
  onChange: PropTypes.func,
@@ -28,15 +28,18 @@ export default class UserTimeDiffFormat extends Component {
28
28
  tzData,
29
29
  timeFormat,
30
30
  datePattern,
31
- dateTimeFormat,
32
- defaulDatePattern,
33
- defaultDateTimeFormat
31
+ isEnabledCurrentYear
34
32
  } = this.context || {};
35
33
 
36
34
  if (!format && !others) {
37
- let pattern = displayType === 'date' ? datePattern : displayType === 'time' ? timeFormat : displayType === 'dateTime' ? dateTimeFormat : '';
38
-
39
- format = () => pattern;
35
+ format = _ref => {
36
+ let {
37
+ dateTimeFormat,
38
+ dateFormat,
39
+ timeFormat
40
+ } = _ref;
41
+ displayType === 'dateTime' ? dateTimeFormat : displayType === 'date' ? dateFormat : timeFormat;
42
+ };
40
43
  }
41
44
 
42
45
  return /*#__PURE__*/React.createElement(DateTimeDiffFormat, {
@@ -59,9 +62,8 @@ export default class UserTimeDiffFormat extends Component {
59
62
  dataId: dataId,
60
63
  isOverdue: isOverdue,
61
64
  timeFormat: timeFormat,
62
- dateTimeFormat: dateTimeFormat,
63
- defaulDatePattern: defaulDatePattern,
64
- defaultDateTimeFormat: defaultDateTimeFormat
65
+ datePattern: datePattern,
66
+ isEnabledCurrentYear: isEnabledCurrentYear
65
67
  });
66
68
  }
67
69