@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/lib/index.js CHANGED
@@ -1,88 +1,83 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- Object.defineProperty(exports, "formatDate", {
9
- enumerable: true,
10
- get: function get() {
11
- return _utils.formatDate;
12
- }
13
- });
14
- Object.defineProperty(exports, "pad", {
8
+ Object.defineProperty(exports, "DateTimeDiffFormat", {
15
9
  enumerable: true,
16
10
  get: function get() {
17
- return _utils.pad;
11
+ return _DateTimeDiffFormat["default"];
18
12
  }
19
13
  });
20
- Object.defineProperty(exports, "replaceI18NValuesWithRegex", {
14
+ Object.defineProperty(exports, "FormatText", {
21
15
  enumerable: true,
22
16
  get: function get() {
23
- return _utils.replaceI18NValuesWithRegex;
17
+ return _FormatText["default"];
24
18
  }
25
19
  });
26
- Object.defineProperty(exports, "unescapeUnicode", {
20
+ Object.defineProperty(exports, "HOCI18N", {
27
21
  enumerable: true,
28
22
  get: function get() {
29
- return _utils.unescapeUnicode;
23
+ return _HOCI18N["default"];
30
24
  }
31
25
  });
32
- Object.defineProperty(exports, "getValues", {
26
+ Object.defineProperty(exports, "I18N", {
33
27
  enumerable: true,
34
28
  get: function get() {
35
- return _utils.getValues;
29
+ return _I18N["default"];
36
30
  }
37
31
  });
38
- Object.defineProperty(exports, "getI18NInfo", {
32
+ Object.defineProperty(exports, "I18NContext", {
39
33
  enumerable: true,
40
34
  get: function get() {
41
- return _utils.getI18NInfo;
35
+ return _I18NContext.I18NContext;
42
36
  }
43
37
  });
44
- Object.defineProperty(exports, "isToday", {
38
+ Object.defineProperty(exports, "I18NProvider", {
45
39
  enumerable: true,
46
40
  get: function get() {
47
- return _utils.isToday;
41
+ return _I18NProvider["default"];
48
42
  }
49
43
  });
50
- Object.defineProperty(exports, "isYesterday", {
44
+ Object.defineProperty(exports, "PluralFormat", {
51
45
  enumerable: true,
52
46
  get: function get() {
53
- return _utils.isYesterday;
47
+ return _PluralFormat["default"];
54
48
  }
55
49
  });
56
- Object.defineProperty(exports, "isTomorrow", {
50
+ Object.defineProperty(exports, "UserTimeDiffFormat", {
57
51
  enumerable: true,
58
52
  get: function get() {
59
- return _utils.isTomorrow;
53
+ return _UserTimeDiffFormat["default"];
60
54
  }
61
55
  });
62
- Object.defineProperty(exports, "isWithinAWeek", {
56
+ Object.defineProperty(exports, "formatDate", {
63
57
  enumerable: true,
64
58
  get: function get() {
65
- return _utils.isWithinAWeek;
59
+ return _utils.formatDate;
66
60
  }
67
61
  });
68
- Object.defineProperty(exports, "isTwoWeeksOrMore", {
62
+ Object.defineProperty(exports, "getDatePatternWithoutYear", {
69
63
  enumerable: true,
70
64
  get: function get() {
71
- return _utils.isTwoWeeksOrMore;
65
+ return _utils.getDatePatternWithoutYear;
72
66
  }
73
67
  });
74
- Object.defineProperty(exports, "userDateFormat", {
68
+ Object.defineProperty(exports, "getDiffObj", {
75
69
  enumerable: true,
76
70
  get: function get() {
77
- return _utils.userDateFormat;
71
+ return _utils.getDiffObj;
78
72
  }
79
73
  });
80
- Object.defineProperty(exports, "getDiffObj", {
74
+ Object.defineProperty(exports, "getI18NInfo", {
81
75
  enumerable: true,
82
76
  get: function get() {
83
- return _utils.getDiffObj;
77
+ return _utils.getI18NInfo;
84
78
  }
85
79
  });
80
+ exports.getI18NValue = void 0;
86
81
  Object.defineProperty(exports, "getLyears", {
87
82
  enumerable: true,
88
83
  get: function get() {
@@ -95,73 +90,78 @@ Object.defineProperty(exports, "getSuffix", {
95
90
  return _utils.getSuffix;
96
91
  }
97
92
  });
98
- Object.defineProperty(exports, "getFormatedDate", {
93
+ Object.defineProperty(exports, "getValues", {
99
94
  enumerable: true,
100
95
  get: function get() {
101
- return _utils.getFormatedDate;
96
+ return _utils.getValues;
102
97
  }
103
98
  });
104
- Object.defineProperty(exports, "I18NContext", {
99
+ Object.defineProperty(exports, "i18NProviderUtils", {
105
100
  enumerable: true,
106
101
  get: function get() {
107
- return _I18NContext.I18NContext;
102
+ return _I18NProvider.i18NProviderUtils;
108
103
  }
109
104
  });
110
- Object.defineProperty(exports, "I18NProvider", {
105
+ Object.defineProperty(exports, "isToday", {
111
106
  enumerable: true,
112
107
  get: function get() {
113
- return _I18NProvider["default"];
108
+ return _utils.isToday;
114
109
  }
115
110
  });
116
- Object.defineProperty(exports, "i18NProviderUtils", {
111
+ Object.defineProperty(exports, "isTomorrow", {
117
112
  enumerable: true,
118
113
  get: function get() {
119
- return _I18NProvider.i18NProviderUtils;
114
+ return _utils.isTomorrow;
120
115
  }
121
116
  });
122
- Object.defineProperty(exports, "I18N", {
117
+ Object.defineProperty(exports, "isTwoWeeksOrMore", {
123
118
  enumerable: true,
124
119
  get: function get() {
125
- return _I18N["default"];
120
+ return _utils.isTwoWeeksOrMore;
126
121
  }
127
122
  });
128
- Object.defineProperty(exports, "HOCI18N", {
123
+ Object.defineProperty(exports, "isWithinAWeek", {
129
124
  enumerable: true,
130
125
  get: function get() {
131
- return _HOCI18N["default"];
126
+ return _utils.isWithinAWeek;
132
127
  }
133
128
  });
134
- Object.defineProperty(exports, "FormatText", {
129
+ Object.defineProperty(exports, "isYesterday", {
135
130
  enumerable: true,
136
131
  get: function get() {
137
- return _FormatText["default"];
132
+ return _utils.isYesterday;
138
133
  }
139
134
  });
140
- Object.defineProperty(exports, "PluralFormat", {
135
+ Object.defineProperty(exports, "pad", {
141
136
  enumerable: true,
142
137
  get: function get() {
143
- return _PluralFormat["default"];
138
+ return _utils.pad;
144
139
  }
145
140
  });
146
- Object.defineProperty(exports, "DateTimeDiffFormat", {
141
+ Object.defineProperty(exports, "replaceI18NValuesWithRegex", {
147
142
  enumerable: true,
148
143
  get: function get() {
149
- return _DateTimeDiffFormat["default"];
144
+ return _utils.replaceI18NValuesWithRegex;
150
145
  }
151
146
  });
152
- Object.defineProperty(exports, "UserTimeDiffFormat", {
147
+ Object.defineProperty(exports, "setLocalizedData", {
153
148
  enumerable: true,
154
149
  get: function get() {
155
- return _UserTimeDiffFormat["default"];
150
+ return _utils.setLocalizedData;
156
151
  }
157
152
  });
158
- Object.defineProperty(exports, "NewDateFormat", {
153
+ Object.defineProperty(exports, "unescapeUnicode", {
159
154
  enumerable: true,
160
155
  get: function get() {
161
- return _NewDateFormat["default"];
156
+ return _utils.unescapeUnicode;
157
+ }
158
+ });
159
+ Object.defineProperty(exports, "userDateFormat", {
160
+ enumerable: true,
161
+ get: function get() {
162
+ return _utils.userDateFormat;
162
163
  }
163
164
  });
164
- exports.getI18NValue = void 0;
165
165
 
166
166
  var _utils = require("./utils");
167
167
 
@@ -181,8 +181,6 @@ var _DateTimeDiffFormat = _interopRequireDefault(require("./components/DateTimeD
181
181
 
182
182
  var _UserTimeDiffFormat = _interopRequireDefault(require("./components/UserTimeDiffFormat"));
183
183
 
184
- var _NewDateFormat = _interopRequireDefault(require("./components/NewDateFormat"));
185
-
186
184
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
187
185
 
188
186
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
package/lib/utils.js CHANGED
@@ -4,28 +4,30 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.formatDate = formatDate;
7
- exports.pad = pad;
8
- exports.replaceI18NValuesWithRegex = replaceI18NValuesWithRegex;
9
- exports.unescapeUnicode = unescapeUnicode;
10
- exports.getValues = getValues;
11
- exports.getI18NValue = getI18NValue;
7
+ exports.getDatePatternWithoutYear = getDatePatternWithoutYear;
8
+ exports.getDiffObj = getDiffObj;
12
9
  exports.getI18NInfo = getI18NInfo;
10
+ exports.getI18NValue = getI18NValue;
11
+ exports.getLocalizedValue = getLocalizedValue;
12
+ exports.getLyears = getLyears;
13
+ exports.getSuffix = getSuffix;
14
+ exports.getValues = getValues;
13
15
  exports.isToday = isToday;
14
- exports.isYesterday = isYesterday;
15
16
  exports.isTomorrow = isTomorrow;
16
- exports.isWithinAWeek = isWithinAWeek;
17
17
  exports.isTwoWeeksOrMore = isTwoWeeksOrMore;
18
+ exports.isWithinAWeek = isWithinAWeek;
19
+ exports.isYesterday = isYesterday;
20
+ exports.pad = pad;
21
+ exports.replaceI18NValuesWithRegex = replaceI18NValuesWithRegex;
22
+ exports.setLocalizedData = setLocalizedData;
23
+ exports.unescapeUnicode = unescapeUnicode;
18
24
  exports.userDateFormat = userDateFormat;
19
- exports.getDiffObj = getDiffObj;
20
- exports.getLyears = getLyears;
21
- exports.getSuffix = getSuffix;
22
- exports.getFormatedDate = getFormatedDate;
23
25
 
24
26
  var _datetimejs = _interopRequireDefault(require("@zohodesk/datetimejs"));
25
27
 
26
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
27
29
 
28
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
30
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
29
31
 
30
32
  var dateFormat = {
31
33
  dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
@@ -159,6 +161,41 @@ function getValues() {
159
161
  });
160
162
  }
161
163
 
164
+ var localizedData = {};
165
+
166
+ function setLocalizedData(data) {
167
+ localizedData = data;
168
+ }
169
+
170
+ function getLocalizedValue() {
171
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
172
+ type = _ref.type,
173
+ moduleName = _ref.moduleName,
174
+ apiName = _ref.apiName,
175
+ fieldValue = _ref.fieldValue;
176
+
177
+ var localizedValue = localizedData;
178
+
179
+ switch (type) {
180
+ case 'field':
181
+ ['Field', moduleName, apiName].map(function (key) {
182
+ localizedValue = localizedValue[key] || '';
183
+ });
184
+ break;
185
+
186
+ case 'picklist':
187
+ ['PickListValue', moduleName, apiName, fieldValue].map(function (key) {
188
+ localizedValue = localizedValue[key] || '';
189
+ });
190
+ break;
191
+
192
+ default:
193
+ return null;
194
+ }
195
+
196
+ return localizedValue || null;
197
+ }
198
+
162
199
  function getI18NValue(i18n) {
163
200
  if (typeof i18n === 'undefined') {
164
201
  return function (key) {
@@ -166,15 +203,16 @@ function getI18NValue(i18n) {
166
203
  };
167
204
  }
168
205
 
169
- return function (key, values) {
206
+ return function (key, values, localizedProps) {
207
+ var localizedValue = localizedProps ? getLocalizedValue(localizedProps) : null;
170
208
  var i18nStr = i18n[key];
171
209
 
172
210
  if (i18nStr === undefined) {
173
- return key;
211
+ return localizedValue || key;
174
212
  }
175
213
 
176
214
  i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
177
- return unescapeUnicode(i18nStr);
215
+ return localizedValue || unescapeUnicode(i18nStr);
178
216
  };
179
217
  } // function getValues(params = [], diff) {
180
218
  // return params.map(param => {
@@ -229,12 +267,35 @@ function isTwoWeeksOrMore(fromDate, toDate) {
229
267
  return !isWithinAWeek(fromDate, toDate);
230
268
  }
231
269
 
232
- function userDateFormat(getI18NValue, timezoneData, timeFormat, defaulDatePattern, defaultDateTimeFormat) {
233
- return function (to, _ref, ago, later) {
234
- var today = _ref.today,
235
- yesterday = _ref.yesterday,
236
- tomorrow = _ref.tomorrow,
237
- others = _ref.others;
270
+ function getDatePatternWithoutYear(datePattern) {
271
+ var dateObj;
272
+ var delemiter;
273
+
274
+ if (datePattern.indexOf('.') !== -1) {
275
+ dateObj = datePattern.split('.');
276
+ delemiter = '.';
277
+ } else if (datePattern.indexOf('-') !== -1) {
278
+ dateObj = datePattern.split('-');
279
+ delemiter = '-';
280
+ } else if (datePattern.indexOf('/') !== -1) {
281
+ dateObj = datePattern.split('/');
282
+ delemiter = '/';
283
+ } else {
284
+ dateObj = datePattern.split(' ');
285
+ delemiter = ' ';
286
+ }
287
+
288
+ return dateObj.filter(function (data) {
289
+ return ['yy', 'yyyy'].indexOf(data) === -1;
290
+ }).join(delemiter);
291
+ }
292
+
293
+ function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isEnabledCurrentYear) {
294
+ return function (to, _ref2, ago, later) {
295
+ var today = _ref2.today,
296
+ yesterday = _ref2.yesterday,
297
+ tomorrow = _ref2.tomorrow,
298
+ others = _ref2.others;
238
299
  var isSuffixEnable = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
239
300
  var format = arguments.length > 5 ? arguments[5] : undefined;
240
301
 
@@ -243,6 +304,8 @@ function userDateFormat(getI18NValue, timezoneData, timeFormat, defaulDatePatter
243
304
  var toDateObj = _datetimejs["default"].toDate(_datetimejs["default"].tz.utcToTz(to, timezoneData));
244
305
 
245
306
  var diffMin = new Date(to).getTime() - new Date().getTime();
307
+ var from = new Date();
308
+ from = from.toISOString();
246
309
  var suffix;
247
310
 
248
311
  if (diffMin < 0) {
@@ -275,12 +338,26 @@ function userDateFormat(getI18NValue, timezoneData, timeFormat, defaulDatePatter
275
338
  seconds: diff.s,
276
339
  years: diff.y,
277
340
  yDays: diff.yd,
341
+ crntYear: new Date(from).getFullYear(),
342
+ tYear: new Date(to).getFullYear(),
278
343
  isWithInAWeek: withInAWeak,
279
344
  suffix: suffix,
280
345
  timeFormat: timeFormat,
281
- datePattern: defaulDatePattern,
282
- dateTimeFormat: defaultDateTimeFormat
283
- }; //var daysDiff = toDateObj.diff(fromDateObj, 'days');
346
+ datePattern: datePattern,
347
+ dateTimePattern: "".concat(datePattern, " ").concat(timeFormat)
348
+ }; //In if condition we'll remove year and set date format if the current year is not required
349
+ //In else part we'll set the date format as it is
350
+
351
+ if (isEnabledCurrentYear === true && diffObj1.years === 0 && diffObj1.tYear === diffObj1.crntYear) {
352
+ var _dateFormat = getDatePatternWithoutYear(datePattern);
353
+
354
+ diffObj1.dateFormat = _dateFormat;
355
+ diffObj1.dateTimeFormat = "".concat(_dateFormat, " ").concat(timeFormat);
356
+ } else {
357
+ diffObj1.dateFormat = datePattern;
358
+ diffObj1.dateTimeFormat = "".concat(datePattern, " ").concat(timeFormat);
359
+ } //var daysDiff = toDateObj.diff(fromDateObj, 'days');
360
+
284
361
 
285
362
  var key = '';
286
363
  var values = [];
@@ -319,10 +396,35 @@ function userDateFormat(getI18NValue, timezoneData, timeFormat, defaulDatePatter
319
396
  text = formatDate(toDateObj, value);
320
397
  }
321
398
  } else {
322
- if (diff.y === 0 && (diff.yd === 0 || diff.yd === 1)) {
323
- var dateObj = new Date(toDateObj);
324
- var curDateObj = new Date(fromDateObj);
399
+ var dateObj = new Date(toDateObj);
400
+ var curDateObj = new Date(fromDateObj);
401
+ var diffDayType = diffObj1.yDays; //In this condition, to calculate different days we have copied it from live --> diffDayType
402
+
403
+ if (isOverdue && dateObj.getDate() < curDateObj.getDate() && diffObj1.yDays == 0) {
404
+ diffDayType = -1;
405
+ }
325
406
 
407
+ if (!isOverdue) {
408
+ var diffHr = dateObj.getHours() - curDateObj.getHours();
409
+
410
+ if (diffHr < 0) {
411
+ diffDayType += 1;
412
+ } else if (diffHr == 0) {
413
+ var diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
414
+
415
+ if (diffMins < 0) {
416
+ diffDayType += 1;
417
+ } else if (diffMins == 0) {
418
+ var diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
419
+
420
+ if (diffSec < 0) {
421
+ diffDayType += 1;
422
+ }
423
+ }
424
+ }
425
+ }
426
+
427
+ if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
326
428
  if (today && dateObj.getDate() === curDateObj.getDate()) {
327
429
  if (_typeof(today) === 'object') {
328
430
  key = today.key;
@@ -338,7 +440,7 @@ function userDateFormat(getI18NValue, timezoneData, timeFormat, defaulDatePatter
338
440
  } else if (typeof yesterday === 'string') {
339
441
  text = formatDate(toDateObj, yesterday);
340
442
  }
341
- } else if (tomorrow && dateObj.getDate() > curDateObj.getDate()) {
443
+ } else if (tomorrow && !isOverdue && diff.y === 0 && diffDayType === 1) {
342
444
  if (_typeof(tomorrow) === 'object') {
343
445
  key = tomorrow.key;
344
446
  values = getValues(tomorrow.params, diffObj);
@@ -439,188 +541,4 @@ function getSuffix(min, ago, later) {
439
541
  }
440
542
 
441
543
  return suffix;
442
- }
443
-
444
- function getFormatedDate(to, today, yesterday, tomorrow, others, ago, later, format, titleFormat, titleString, calculateFrom, timezoneData) {
445
- var fromDateObj = _datetimejs["default"].toDate(_datetimejs["default"].tz.utcToTz(calculateFrom, timezoneData));
446
-
447
- var toDateObj = _datetimejs["default"].toDate(_datetimejs["default"].tz.utcToTz(to, timezoneData));
448
-
449
- var diffMin = new Date(to).getTime() - new Date(calculateFrom).getTime();
450
- var suffix = getSuffix(diffMin, ago, later);
451
- var diff = getDiffObj(diffMin);
452
- var withInAWeak = diff.y === 0 && diff.yd <= 7;
453
- var diffObj = {
454
- h: diff.h,
455
- m: diff.m,
456
- s: diff.s,
457
- y: diff.y,
458
- hh: pad(diff.h, 2),
459
- mm: pad(diff.m, 2),
460
- ss: pad(diff.s, 2),
461
- yy: pad(diff.y, 2),
462
- days: diff.yd,
463
- yDays: pad(diff.yd, 2),
464
- isWithInAWeek: withInAWeak,
465
- suffix: suffix
466
- };
467
- var diffObj1 = {
468
- hours: diff.h,
469
- minutes: diff.m,
470
- seconds: diff.s,
471
- years: diff.y,
472
- yDays: diff.yd,
473
- isWithInAWeek: withInAWeak,
474
- suffix: suffix,
475
- crntMonth: new Date(to).getMonth(),
476
- betweenleepYears: getLyears(calculateFrom, to)
477
- }; //var daysDiff = toDateObj.diff(fromDateObj, 'days', true);
478
-
479
- var key = '';
480
- var values = [];
481
- var text = null;
482
- var isSuffixEnable = false;
483
-
484
- if (format) {
485
- var years, months, days, hours, minutes, seconds;
486
- years = diffObj1.years > 1 ? '2' : diffObj1.years; // months = diffObj1.months > 1 ? '2' : diffObj1.months;
487
- //days = diffObj1.days > 1 ? '2' : diffObj1.days;
488
-
489
- days = diff.yd > 1 ? '2' : diff.yd;
490
- hours = diffObj1.hours > 1 ? '2' : diffObj1.hours;
491
- minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes; //seconds = diffObj1.seconds > 1 ? '2' : diffObj1.seconds;
492
- // let pattern = '' + years + months + days + hours + minutes + seconds;
493
-
494
- var count = 0;
495
- var pattern = [years, days, hours, minutes].reduce(function (res, next) {
496
- if (count === 2) {
497
- res = "".concat(res, "0");
498
- } else if (next !== 0) {
499
- count++;
500
- res = res + next;
501
- } else {
502
- res = res + next;
503
- }
504
-
505
- return res;
506
- }, ''); //let pattern = '' + years + days + hours + minutes;
507
-
508
- var _value3 = format(diffObj1, pattern);
509
-
510
- if (_value3 && _typeof(_value3) === 'object') {
511
- key = _value3.key;
512
- values = getValues(_value3.params, diffObj);
513
-
514
- if (pattern.indexOf('00000') === 0) {
515
- //suffix ignore for second hook
516
- isSuffixEnable = false;
517
- } else {
518
- isSuffixEnable = true;
519
- }
520
- } else if (typeof _value3 === 'string') {
521
- if (_value3 === 'socialFormat') {
522
- var defaultRelativeTime = {
523
- future: function future(t) {
524
- return "in ".concat(t);
525
- },
526
- past: function past(t) {
527
- return "".concat(t, " ago");
528
- },
529
- present: function present() {
530
- return 'just now';
531
- },
532
- s: function s() {
533
- return 'a few seconds ago';
534
- },
535
- ss: function ss(t) {
536
- return "".concat(t, " seconds ago");
537
- },
538
- m: function m() {
539
- return 'a minute ago';
540
- },
541
- mm: function mm(t) {
542
- return "".concat(t, " minutes ago");
543
- },
544
- h: function h() {
545
- return 'an hour ago';
546
- },
547
- hh: function hh(t) {
548
- return "".concat(t, " hours ago");
549
- },
550
- d: function d() {
551
- return 'a day ago';
552
- },
553
- dd: function dd(t) {
554
- return "".concat(t, " days ago");
555
- },
556
- M: function M() {
557
- return 'a month ago';
558
- },
559
- MM: function MM(t) {
560
- return "".concat(t, " months ago");
561
- },
562
- y: function y() {
563
- return 'a year ago';
564
- },
565
- yy: function yy(t) {
566
- return "".concat(t, " years ago");
567
- }
568
- };
569
-
570
- if (diff.yd === 0) {
571
- if (diffObj.h < 1) {
572
- if (diffObj.m < 1) {
573
- if (diffObj.s < 1) {
574
- text = defaultRelativeTime.present();
575
- } else if (diffObj.s === 1) {
576
- text = defaultRelativeTime.s();
577
- } else {
578
- text = defaultRelativeTime.ss(diffObj.s);
579
- }
580
- } else if (diffObj.m === 1) {
581
- text = defaultRelativeTime.m();
582
- } else {
583
- text = defaultRelativeTime.mm(diffObj.mm);
584
- }
585
- } else if (diffObj.h === 1) {
586
- text = defaultRelativeTime.h();
587
- } else {
588
- text = defaultRelativeTime.hh(diffObj.h);
589
- }
590
- } else {
591
- text = formatDate(toDateObj, 'DD MMM YYYY', diffObj1);
592
- }
593
- } else {
594
- text = formatDate(toDateObj, _value3, diffObj1);
595
- }
596
- }
597
- } else {
598
- if (diff.y === 0 && (diff.yd === 0 || diff.yd === 1)) {
599
- var dateObj = new Date(toDateObj);
600
- var curDateObj = new Date(fromDateObj);
601
-
602
- if (dateObj.getDate() === curDateObj.getDate()) {
603
- var value = today(diffObj1);
604
- text = formatDate(toDateObj, today);
605
- } else if (dateObj.getMonth() < curDateObj.getMonth() || dateObj.getDate() < curDateObj.getDate()) {
606
- var value = yesterday(diffObj1);
607
- text = formatDate(toDateObj, yesterday);
608
- } else if (dateObj.getMonth() > curDateObj.getMonth() || dateObj.getDate() > curDateObj.getDate()) {
609
- var value = tomorrow(diffObj1);
610
- text = formatDate(toDateObj, value);
611
- }
612
- } else {
613
- var value = others(diffObj1);
614
- text = formatDate(toDateObj, value);
615
- }
616
- }
617
-
618
- var i18nText = isSuffixEnable && suffix !== '' ? "".concat(key, ".").concat(suffix) : key;
619
- var titleFormated = titleString === undefined ? formatDate(to, titleFormat) : titleString;
620
- return {
621
- formatedDate: text,
622
- values: values,
623
- i18nText: i18nText,
624
- title: titleFormated
625
- };
626
544
  }