@zohodesk/i18n 1.0.0-beta.33 → 1.0.0-beta.35-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 (52) hide show
  1. package/README.md +4 -0
  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/components/DateTimeDiffFormat.js +5 -19
  10. package/es/components/FormatText.js +2 -2
  11. package/es/components/HOCI18N.js +32 -43
  12. package/es/components/I18N.js +2 -13
  13. package/es/components/I18NProvider.js +0 -9
  14. package/es/components/PluralFormat.js +3 -5
  15. package/es/components/UserTimeDiffFormat.js +5 -9
  16. package/es/components/__tests__/DateTimeDiffFormat.spec.js +157 -221
  17. package/es/components/__tests__/FormatText.spec.js +2 -2
  18. package/es/components/__tests__/HOCI18N.spec.js +2 -4
  19. package/es/components/__tests__/I18N.spec.js +6 -4
  20. package/es/components/__tests__/I18NProvider.spec.js +4 -4
  21. package/es/components/__tests__/PluralFormat.spec.js +2 -2
  22. package/es/components/__tests__/UserTimeDiffFormat.spec.js +249 -348
  23. package/es/index.js +2 -0
  24. package/es/utils/__tests__/jsxTranslations.spec.js +3 -7
  25. package/es/utils/errorReporter.js +31 -0
  26. package/es/utils/index.js +42 -92
  27. package/es/utils/jsxTranslations.js +53 -61
  28. package/lib/I18NContext.js +2 -7
  29. package/lib/components/DateTimeDiffFormat.js +46 -87
  30. package/lib/components/FormatText.js +18 -41
  31. package/lib/components/HOCI18N.js +24 -59
  32. package/lib/components/I18N.js +27 -64
  33. package/lib/components/I18NProvider.js +27 -63
  34. package/lib/components/PluralFormat.js +24 -50
  35. package/lib/components/UserTimeDiffFormat.js +43 -72
  36. package/lib/components/__tests__/DateTimeDiffFormat.spec.js +95 -165
  37. package/lib/components/__tests__/FormatText.spec.js +3 -10
  38. package/lib/components/__tests__/HOCI18N.spec.js +3 -14
  39. package/lib/components/__tests__/I18N.spec.js +4 -12
  40. package/lib/components/__tests__/I18NProvider.spec.js +8 -23
  41. package/lib/components/__tests__/PluralFormat.spec.js +3 -11
  42. package/lib/components/__tests__/UserTimeDiffFormat.spec.js +157 -225
  43. package/lib/index.js +32 -22
  44. package/lib/utils/__tests__/jsxTranslations.spec.js +1 -12
  45. package/lib/utils/errorReporter.js +39 -0
  46. package/lib/utils/index.js +49 -125
  47. package/lib/utils/jsxTranslations.js +79 -105
  48. package/package.json +1 -1
  49. package/src/index.js +6 -0
  50. package/src/utils/errorReporter.js +36 -0
  51. package/src/utils/index.js +8 -1
  52. package/src/utils/jsxTranslations.js +31 -12
@@ -27,20 +27,15 @@ exports.setLocalizedData = setLocalizedData;
27
27
  exports.timei18n = void 0;
28
28
  exports.unescapeUnicode = unescapeUnicode;
29
29
  exports.userDateFormat = userDateFormat;
30
-
31
30
  var _datetimejs = _interopRequireDefault(require("@zohodesk/datetimejs"));
32
-
33
31
  var _I18NProvider = require("../components/I18NProvider");
34
-
35
- var _monthi18n;
36
-
37
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
38
-
39
- 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); }
40
-
41
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
42
-
43
- var dayi18n = {
32
+ var _errorReporter = require("./errorReporter");
33
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
34
+ 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); }
35
+ 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; }
36
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
37
+ 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); }
38
+ var dayi18n = exports.dayi18n = {
44
39
  'Sun': 'deskreact.calendar.daynameshort.sunday',
45
40
  'Mon': 'deskreact.calendar.daynameshort.monday',
46
41
  'Tue': 'deskreact.calendar.daynameshort.tuesday',
@@ -56,8 +51,7 @@ var dayi18n = {
56
51
  'Friday': 'deskreact.calendar.dayname.friday',
57
52
  'Saturday': 'deskreact.calendar.dayname.saturday'
58
53
  };
59
- exports.dayi18n = dayi18n;
60
- var monthi18n = (_monthi18n = {
54
+ var monthi18n = exports.monthi18n = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
61
55
  'Jan': 'deskreact.calendar.monthnameshort.january',
62
56
  'Feb': 'deskreact.calendar.monthnameshort.february',
63
57
  'Mar': 'deskreact.calendar.monthnameshort.march',
@@ -74,9 +68,8 @@ var monthi18n = (_monthi18n = {
74
68
  'February': 'deskreact.calendar.monthname.february',
75
69
  'March': 'deskreact.calendar.monthname.march',
76
70
  'April': 'deskreact.calendar.monthname.april'
77
- }, _defineProperty(_monthi18n, "May", 'deskreact.calendar.monthname.may'), _defineProperty(_monthi18n, 'June', 'deskreact.calendar.monthname.june'), _defineProperty(_monthi18n, 'July', 'deskreact.calendar.monthname.july'), _defineProperty(_monthi18n, 'August', 'deskreact.calendar.monthname.august'), _defineProperty(_monthi18n, 'September', 'deskreact.calendar.monthname.september'), _defineProperty(_monthi18n, 'October', 'deskreact.calendar.monthname.october'), _defineProperty(_monthi18n, 'November', 'deskreact.calendar.monthname.november'), _defineProperty(_monthi18n, 'December', 'deskreact.calendar.monthname.december'), _monthi18n);
78
- exports.monthi18n = monthi18n;
79
- var timei18n = {
71
+ }, "May", 'deskreact.calendar.monthname.may'), 'June', 'deskreact.calendar.monthname.june'), 'July', 'deskreact.calendar.monthname.july'), 'August', 'deskreact.calendar.monthname.august'), 'September', 'deskreact.calendar.monthname.september'), 'October', 'deskreact.calendar.monthname.october'), 'November', 'deskreact.calendar.monthname.november'), 'December', 'deskreact.calendar.monthname.december');
72
+ var timei18n = exports.timei18n = {
80
73
  'a': 'support.time.format.time.am.short.small',
81
74
  'p': 'support.time.format.time.pm.short.small',
82
75
  'am': 'support.time.format.time.am.small',
@@ -86,52 +79,43 @@ var timei18n = {
86
79
  'AM': 'deskreact.calendar.ampmtext.am',
87
80
  'PM': 'deskreact.calendar.ampmtext.pm'
88
81
  };
89
- exports.timei18n = timei18n;
90
82
  var dateFormat = {
91
83
  dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
92
84
  monthNames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
93
85
  timeNames: ['a', 'p', 'am', 'pm', 'A', 'P', 'AM', 'PM']
94
86
  };
95
-
96
87
  function formatDate(dateMill, mask, dateDiffObj) {
97
88
  if (mask === 'facebookFormat') {
98
89
  var hours = dateDiffObj.hours,
99
- minutes = dateDiffObj.minutes,
100
- seconds = dateDiffObj.seconds,
101
- yDays = dateDiffObj.yDays,
102
- years = dateDiffObj.years,
103
- betweenleepYears = dateDiffObj.betweenleepYears,
104
- crntMonth = dateDiffObj.crntMonth;
105
-
90
+ minutes = dateDiffObj.minutes,
91
+ seconds = dateDiffObj.seconds,
92
+ yDays = dateDiffObj.yDays,
93
+ years = dateDiffObj.years,
94
+ betweenleepYears = dateDiffObj.betweenleepYears,
95
+ crntMonth = dateDiffObj.crntMonth;
106
96
  if (years > 0) {
107
97
  return "".concat(years, "y");
108
98
  } else if (yDays > 0) {
109
99
  var isFeb = crntMonth === 1;
110
100
  var isThoneMonth = [0, 2, 4, 6, 7, 9, 11].indexOf(crntMonth) != -1;
111
-
112
101
  var weekCal = function weekCal(calDays) {
113
102
  var weeks = calDays / 7;
114
103
  return weeks < 1 ? "".concat(calDays, "d") : "".concat(Math.trunc(weeks), "w");
115
104
  };
116
-
117
105
  if (!isFeb) {
118
106
  return isThoneMonth === true ? yDays === 31 ? '1m' : weekCal(yDays) : yDays === 30 ? '1m' : weekCal(yDays);
119
107
  }
120
-
121
108
  if (betweenleepYears != 0) {
122
109
  return isFeb === true && yDays === 28 ? '1m' : weekCal(yDays);
123
110
  }
124
-
125
111
  return isFeb === true && yDays === 29 ? '1m' : weekCal(yDays);
126
112
  } else if (hours < 24 && hours > 0) {
127
113
  return "".concat(hours, "h");
128
114
  } else if (minutes < 60 && hours > 1) {
129
115
  return "".concat(minutes, "m");
130
116
  }
131
-
132
117
  return seconds === 0 ? 'now' : "".concat(seconds, "s");
133
118
  }
134
-
135
119
  var date = new Date(dateMill);
136
120
  var d = date.getDate();
137
121
  var D = date.getDay();
@@ -177,12 +161,10 @@ function formatDate(dateMill, mask, dateDiffObj) {
177
161
  if (match in flags) {
178
162
  return flags[match];
179
163
  }
180
-
181
164
  return match.slice(1, match.length - 1);
182
165
  });
183
166
  return dat;
184
167
  }
185
-
186
168
  function pad(n) {
187
169
  var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
188
170
  var z = arguments.length > 2 ? arguments[2] : undefined;
@@ -190,7 +172,6 @@ function pad(n) {
190
172
  n = "".concat(n);
191
173
  return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
192
174
  }
193
-
194
175
  function replaceI18NValuesWithRegex(i18nStr, values) {
195
176
  if (typeof values !== 'undefined') {
196
177
  if (Array.isArray(values)) {
@@ -201,16 +182,13 @@ function replaceI18NValuesWithRegex(i18nStr, values) {
201
182
  i18nStr = i18nStr.replace(new RegExp('\\{0\\}', 'g'), values);
202
183
  }
203
184
  }
204
-
205
185
  return i18nStr;
206
186
  }
207
-
208
187
  function unescapeUnicode(str) {
209
188
  return str.replace(/\\u([a-fA-F0-9]{4})/g, function (g, m1) {
210
189
  return String.fromCharCode(parseInt(m1, 16));
211
190
  });
212
191
  }
213
-
214
192
  function getValues() {
215
193
  var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
216
194
  var diff = arguments.length > 1 ? arguments[1] : undefined;
@@ -218,72 +196,58 @@ function getValues() {
218
196
  return diff[param];
219
197
  });
220
198
  }
221
-
222
199
  function isObject(item) {
223
200
  return item && _typeof(item) === 'object' && !Array.isArray(item);
224
201
  }
225
-
226
202
  var localizedData = {};
227
203
  var localizedStringData = {};
228
-
229
204
  var getMappedKey = function getMappedKey(key) {
230
205
  return key;
231
206
  };
232
-
233
207
  function setLocalizedStringData(data) {
234
208
  var keyString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
235
-
236
209
  if (typeof data === 'string') {
237
210
  localizedStringData[keyString] = data;
238
211
  return;
239
212
  }
240
-
241
213
  var keys = Object.keys(data);
242
-
243
214
  for (var i = 0; i < keys.length; i++) {
244
215
  var _key = keys[i];
245
216
  var newKeyString = keyString ? "".concat(keyString, ".").concat(_key) : _key;
246
217
  setLocalizedStringData(data[_key], newKeyString);
247
218
  }
248
219
  }
249
-
250
220
  function setLocalizedData(data) {
251
221
  var translationData = isObject(data) ? data : {};
252
222
  localizedData = translationData;
253
223
  setLocalizedStringData(translationData);
254
224
  }
255
-
256
225
  function setI18NKeyMapping(func) {
257
226
  getMappedKey = func;
258
227
  }
259
-
260
228
  function getLocalizedValue() {
261
229
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
262
- type = _ref.type,
263
- moduleName = _ref.moduleName,
264
- deptName = _ref.deptName,
265
- folderName = _ref.folderName,
266
- reportId = _ref.reportId,
267
- reportName = _ref.reportName,
268
- apiName = _ref.apiName,
269
- fieldValue = _ref.fieldValue,
270
- layoutName = _ref.layoutName;
271
-
230
+ type = _ref.type,
231
+ moduleName = _ref.moduleName,
232
+ deptName = _ref.deptName,
233
+ folderName = _ref.folderName,
234
+ reportId = _ref.reportId,
235
+ reportName = _ref.reportName,
236
+ apiName = _ref.apiName,
237
+ fieldValue = _ref.fieldValue,
238
+ layoutName = _ref.layoutName;
272
239
  var localizedValue = localizedData;
273
-
274
240
  switch (type) {
275
241
  case 'field':
276
242
  ['Field', moduleName, apiName].map(function (key) {
277
243
  localizedValue = localizedValue[key] || '';
278
244
  });
279
245
  break;
280
-
281
246
  case 'picklist':
282
247
  ['PickListValue', moduleName, apiName, fieldValue].map(function (key) {
283
248
  localizedValue = localizedValue[key] || '';
284
249
  });
285
250
  break;
286
-
287
251
  case 'layout':
288
252
  if (deptName != null) {
289
253
  ['Layout', moduleName, deptName, layoutName].map(function () {
@@ -294,52 +258,46 @@ function getLocalizedValue() {
294
258
  localizedValue = localizedValue[key] || '';
295
259
  });
296
260
  }
297
-
298
261
  break;
299
-
300
262
  case 'report':
301
263
  ['Report', deptName, folderName, reportName, reportId].map(function (key) {
302
264
  localizedValue = localizedValue[key] || '';
303
265
  });
304
-
305
266
  default:
306
267
  return null;
307
268
  }
308
-
309
269
  return localizedValue || null;
310
270
  }
311
-
312
271
  function getI18NValue(i18n) {
313
272
  if (typeof i18n === 'undefined') {
273
+ (0, _errorReporter.reportI18NError)(_errorReporter.I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object');
314
274
  return function (key) {
315
275
  return key;
316
276
  };
317
277
  }
318
-
319
278
  return function (key, values, localizedProps) {
320
279
  var localizedValue = localizedProps ? getLocalizedValue(localizedProps) : localizedStringData[key];
321
280
  var finalKey = getMappedKey(key);
322
281
  var i18nStr = i18n[finalKey];
323
-
324
282
  if (i18nStr === undefined) {
325
- return localizedValue || finalKey;
283
+ var isNumeric = /^\d+$/.test(finalKey);
284
+ (0, _errorReporter.reportI18NError)(isNumeric ? _errorReporter.I18N_ERROR_TYPES.NUMERIC_FALLBACK : _errorReporter.I18N_ERROR_TYPES.MISSING_KEY, finalKey);
285
+ return localizedValue || getFallbackText(finalKey);
326
286
  }
327
-
328
287
  i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
329
288
  return localizedValue || unescapeUnicode(i18nStr);
330
289
  };
331
- } // function getValues(params = [], diff) {
290
+ }
291
+
292
+ // function getValues(params = [], diff) {
332
293
  // return params.map(param => {
333
294
  // return diff[param];
334
295
  // });
335
296
  // }
336
-
337
-
338
297
  function getI18NInfo(toDateObj, props, diffObj) {
339
298
  var key = null,
340
- values,
341
- text = null;
342
-
299
+ values,
300
+ text = null;
343
301
  if (typeof props === 'function') {
344
302
  var value = props(diffObj1);
345
303
  key = value.key;
@@ -350,41 +308,33 @@ function getI18NInfo(toDateObj, props, diffObj) {
350
308
  } else if (typeof props === 'string') {
351
309
  text = toDateObj.format(props);
352
310
  }
353
-
354
311
  return {
355
312
  key: key,
356
313
  values: values,
357
314
  text: text
358
315
  };
359
316
  }
360
-
361
317
  function isToday(fromDate, toDate) {
362
318
  var TODAY = toDate.clone().startOf('day');
363
319
  return fromDate.isSame(TODAY, 'd');
364
320
  }
365
-
366
321
  function isYesterday(fromDate, toDate) {
367
322
  var YESTERDAY = toDate.clone().subtract(1, 'days').startOf('day');
368
323
  return fromDate.isSame(YESTERDAY, 'd');
369
324
  }
370
-
371
325
  function isTomorrow(fromDate, toDate) {
372
326
  return isYesterday(toDate, fromDate);
373
327
  }
374
-
375
328
  function isWithinAWeek(fromDate, toDate) {
376
329
  var A_WEEK_OLD = toDate.clone().subtract(7, 'days').startOf('day');
377
330
  return fromDate.isAfter(A_WEEK_OLD);
378
331
  }
379
-
380
332
  function isTwoWeeksOrMore(fromDate, toDate) {
381
333
  return !isWithinAWeek(fromDate, toDate);
382
334
  }
383
-
384
335
  function getDatePatternWithoutYear(datePattern) {
385
336
  var dateObj;
386
337
  var delemiter;
387
-
388
338
  if (datePattern.indexOf('.') !== -1) {
389
339
  dateObj = datePattern.split('.');
390
340
  delemiter = '.';
@@ -398,30 +348,24 @@ function getDatePatternWithoutYear(datePattern) {
398
348
  dateObj = datePattern.split(' ');
399
349
  delemiter = ' ';
400
350
  }
401
-
402
351
  return dateObj.filter(function (data) {
403
352
  return ['yy', 'yyyy'].indexOf(data) === -1;
404
353
  }).join(delemiter);
405
354
  }
406
-
407
355
  function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isEnabledCurrentYear) {
408
356
  return function (to, _ref2, ago, later) {
409
357
  var today = _ref2.today,
410
- yesterday = _ref2.yesterday,
411
- tomorrow = _ref2.tomorrow,
412
- others = _ref2.others;
358
+ yesterday = _ref2.yesterday,
359
+ tomorrow = _ref2.tomorrow,
360
+ others = _ref2.others;
413
361
  var isSuffixEnable = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
414
362
  var format = arguments.length > 5 ? arguments[5] : undefined;
415
-
416
363
  var fromDateObj = _datetimejs["default"].toDate(_datetimejs["default"].tz.utcToTz(null, timezoneData));
417
-
418
364
  var toDateObj = _datetimejs["default"].toDate(_datetimejs["default"].tz.utcToTz(to, timezoneData));
419
-
420
365
  var diffMin = new Date(to).getTime() - new Date().getTime();
421
366
  var from = new Date();
422
367
  from = from.toISOString();
423
368
  var suffix;
424
-
425
369
  if (diffMin < 0) {
426
370
  suffix = ago || '';
427
371
  } else if (diffMin > 0) {
@@ -429,7 +373,6 @@ function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isE
429
373
  } else {
430
374
  suffix = '';
431
375
  }
432
-
433
376
  var diff = getDiffObj(diffMin);
434
377
  var withInAWeak = diff.y === 0 && diff.yd <= 7;
435
378
  var diffObj = {
@@ -459,34 +402,34 @@ function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isE
459
402
  timeFormat: timeFormat,
460
403
  datePattern: datePattern,
461
404
  dateTimePattern: "".concat(datePattern, " ").concat(timeFormat)
462
- }; //In if condition we'll remove year and set date format if the current year is not required
463
- //In else part we'll set the date format as it is
405
+ };
464
406
 
407
+ //In if condition we'll remove year and set date format if the current year is not required
408
+ //In else part we'll set the date format as it is
465
409
  if (isEnabledCurrentYear === true && diffObj1.years === 0 && diffObj1.tYear === diffObj1.crntYear) {
466
410
  var _dateFormat = getDatePatternWithoutYear(datePattern);
467
-
468
411
  diffObj1.dateFormat = _dateFormat;
469
412
  diffObj1.dateTimeFormat = "".concat(_dateFormat, " ").concat(timeFormat);
470
413
  } else {
471
414
  diffObj1.dateFormat = datePattern;
472
415
  diffObj1.dateTimeFormat = "".concat(datePattern, " ").concat(timeFormat);
473
- } //var daysDiff = toDateObj.diff(fromDateObj, 'days');
416
+ }
474
417
 
418
+ //var daysDiff = toDateObj.diff(fromDateObj, 'days');
475
419
 
476
420
  var key = '';
477
421
  var values = [];
478
422
  var text = null;
479
-
480
423
  if (format) {
481
424
  var years, months, days, hours, minutes, seconds;
482
- years = diffObj1.years > 1 ? '2' : diffObj1.years; // months = diffObj1.months > 1 ? '2' : diffObj1.months;
425
+ years = diffObj1.years > 1 ? '2' : diffObj1.years;
426
+ // months = diffObj1.months > 1 ? '2' : diffObj1.months;
483
427
  // days = diffObj1.days > 1 ? '2' : diffObj1.days;
484
-
485
428
  days = diff.yd > 1 ? '2' : diff.yd;
486
429
  hours = diffObj1.hours > 1 ? '2' : diffObj1.hours;
487
- minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes; //seconds = diffObj1.seconds > 1 ? '2' : diffObj1.seconds;
430
+ minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes;
431
+ //seconds = diffObj1.seconds > 1 ? '2' : diffObj1.seconds;
488
432
  // let pattern = '' + years + months + days + hours + minutes + seconds;
489
-
490
433
  var count = 0;
491
434
  var pattern = [years, days, hours, minutes].reduce(function (res, next) {
492
435
  if (count === 2 || next === 0) {
@@ -497,11 +440,9 @@ function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isE
497
440
  } else {
498
441
  res = res + next;
499
442
  }
500
-
501
443
  return res;
502
444
  }, '');
503
445
  var value = format(diffObj1, pattern);
504
-
505
446
  if (value && _typeof(value) === 'object') {
506
447
  key = value.key;
507
448
  values = getValues(value.params, diffObj);
@@ -512,32 +453,28 @@ function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isE
512
453
  } else {
513
454
  var dateObj = new Date(toDateObj);
514
455
  var curDateObj = new Date(fromDateObj);
515
- var diffDayType = diffObj1.yDays; //In this condition, to calculate different days we have copied it from live --> diffDayType
456
+ var diffDayType = diffObj1.yDays;
516
457
 
458
+ //In this condition, to calculate different days we have copied it from live --> diffDayType
517
459
  if (isOverdue && dateObj.getDate() < curDateObj.getDate() && diffObj1.yDays == 0) {
518
460
  diffDayType = -1;
519
461
  }
520
-
521
462
  if (!isOverdue) {
522
463
  var diffHr = dateObj.getHours() - curDateObj.getHours();
523
-
524
464
  if (diffHr < 0) {
525
465
  diffDayType += 1;
526
466
  } else if (diffHr == 0) {
527
467
  var diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
528
-
529
468
  if (diffMins < 0) {
530
469
  diffDayType += 1;
531
470
  } else if (diffMins == 0) {
532
471
  var diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
533
-
534
472
  if (diffSec < 0) {
535
473
  diffDayType += 1;
536
474
  }
537
475
  }
538
476
  }
539
477
  }
540
-
541
478
  if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
542
479
  if (today && dateObj.getDate() === curDateObj.getDate()) {
543
480
  if (_typeof(today) === 'object') {
@@ -563,7 +500,6 @@ function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isE
563
500
  }
564
501
  } else {
565
502
  var _value = others(diffObj1);
566
-
567
503
  if (_typeof(_value) === 'object') {
568
504
  key = _value.key;
569
505
  values = getValues(_value.params, diffObj);
@@ -574,7 +510,6 @@ function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isE
574
510
  }
575
511
  } else {
576
512
  var _value2 = others(diffObj1);
577
-
578
513
  if (_typeof(_value2) === 'object') {
579
514
  key = _value2.key;
580
515
  values = getValues(_value2.params, diffObj);
@@ -584,25 +519,20 @@ function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isE
584
519
  }
585
520
  }
586
521
  }
587
-
588
522
  var key1 = isSuffixEnable && suffix != '' ? "".concat(key, ".").concat(suffix) : key;
589
523
  return text || getI18NValue(key1, values);
590
524
  };
591
525
  }
592
-
593
526
  var oneYearInMillis = 31536000000;
594
527
  var oneDayInMillis = 86400000;
595
528
  var oneHourInMillis = 3600000;
596
529
  var oneMinuteInMillis = 60000;
597
-
598
530
  function convertAsNonExponential(number) {
599
531
  if (number.toString().toLowerCase().indexOf('e') !== -1) {
600
532
  return number.toFixed(20);
601
533
  }
602
-
603
534
  return number;
604
535
  }
605
-
606
536
  function getDiffObj(diff) {
607
537
  diff = Math.abs(diff);
608
538
  var diffYears = diff / oneYearInMillis;
@@ -626,26 +556,21 @@ function getDiffObj(diff) {
626
556
  s: diffSeconds
627
557
  };
628
558
  }
629
-
630
559
  function getLyears(from, to) {
631
560
  var dFrom = new Date(from),
632
- dTo = new Date(to);
561
+ dTo = new Date(to);
633
562
  var fromYear = dFrom.getFullYear();
634
563
  var toYear = dTo.getFullYear();
635
564
  var arrayofLeapYears = [];
636
-
637
565
  for (var loopYear = fromYear; loopYear <= toYear; loopYear++) {
638
566
  if (loopYear % 4 === 0 && loopYear % 100 !== 0 || loopYear % 100 === 0 && loopYear % 400 === 0) {
639
567
  arrayofLeapYears.push(loopYear);
640
568
  }
641
569
  }
642
-
643
570
  return arrayofLeapYears.length;
644
571
  }
645
-
646
572
  function getSuffix(min, ago, later) {
647
573
  var suffix;
648
-
649
574
  if (min < 0) {
650
575
  suffix = ago || '';
651
576
  } else if (min > 0) {
@@ -653,6 +578,5 @@ function getSuffix(min, ago, later) {
653
578
  } else {
654
579
  suffix = '';
655
580
  }
656
-
657
581
  return suffix;
658
582
  }