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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +130 -4
  2. package/docs/murphy/01-MURPHY_OVERVIEW.md +148 -0
  3. package/docs/murphy/02-MURPHY_ARCHITECTURE.md +283 -0
  4. package/docs/murphy/03-MURPHY_BACKEND_CONFIG.md +337 -0
  5. package/docs/murphy/04-MURPHY_FRONTEND_INIT.md +437 -0
  6. package/docs/murphy/05-MURPHY_DESK_CLIENT_USAGE.md +467 -0
  7. package/docs/murphy/06-MURPHY_I18N_INTEGRATION.md +402 -0
  8. package/docs/murphy/07-MURPHY_WHY_I18N_APPROACH.md +391 -0
  9. package/es/I18NContext.js +1 -2
  10. package/es/components/DateTimeDiffFormat.js +185 -209
  11. package/es/components/FormatText.js +7 -27
  12. package/es/components/HOCI18N.js +35 -58
  13. package/es/components/I18N.js +48 -74
  14. package/es/components/I18NProvider.js +59 -93
  15. package/es/components/PluralFormat.js +28 -51
  16. package/es/components/UserTimeDiffFormat.js +66 -81
  17. package/es/components/__tests__/DateTimeDiffFormat.spec.js +810 -663
  18. package/es/components/__tests__/FormatText.spec.js +22 -19
  19. package/es/components/__tests__/HOCI18N.spec.js +19 -25
  20. package/es/components/__tests__/I18N.spec.js +23 -21
  21. package/es/components/__tests__/I18NProvider.spec.js +38 -47
  22. package/es/components/__tests__/PluralFormat.spec.js +23 -20
  23. package/es/components/__tests__/UserTimeDiffFormat.spec.js +1259 -1110
  24. package/es/index.js +13 -15
  25. package/es/utils/__tests__/jsxTranslations.spec.js +170 -0
  26. package/es/utils/errorReporter.js +41 -0
  27. package/es/utils/index.js +543 -0
  28. package/es/utils/jsxTranslations.js +185 -0
  29. package/lib/I18NContext.js +5 -10
  30. package/lib/components/DateTimeDiffFormat.js +131 -146
  31. package/lib/components/FormatText.js +29 -42
  32. package/lib/components/HOCI18N.js +34 -45
  33. package/lib/components/I18N.js +46 -57
  34. package/lib/components/I18NProvider.js +72 -95
  35. package/lib/components/PluralFormat.js +39 -55
  36. package/lib/components/UserTimeDiffFormat.js +76 -84
  37. package/lib/components/__tests__/DateTimeDiffFormat.spec.js +751 -635
  38. package/lib/components/__tests__/FormatText.spec.js +21 -30
  39. package/lib/components/__tests__/HOCI18N.spec.js +22 -41
  40. package/lib/components/__tests__/I18N.spec.js +20 -33
  41. package/lib/components/__tests__/I18NProvider.spec.js +40 -63
  42. package/lib/components/__tests__/PluralFormat.spec.js +23 -35
  43. package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1195 -1046
  44. package/lib/index.js +83 -104
  45. package/lib/utils/__tests__/jsxTranslations.spec.js +172 -0
  46. package/lib/utils/errorReporter.js +49 -0
  47. package/lib/utils/index.js +583 -0
  48. package/lib/utils/jsxTranslations.js +216 -0
  49. package/package.json +4 -3
  50. package/src/components/DateTimeDiffFormat.js +84 -55
  51. package/src/components/I18N.js +2 -0
  52. package/src/components/I18NProvider.js +44 -33
  53. package/src/components/UserTimeDiffFormat.js +22 -18
  54. package/src/index.js +12 -9
  55. package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
  56. package/src/utils/errorReporter.js +48 -0
  57. package/src/utils/index.js +644 -0
  58. package/src/utils/jsxTranslations.js +199 -0
  59. package/es/components/NewDateFormat.js +0 -50
  60. package/es/offset.js +0 -629
  61. package/es/timezones.js +0 -118
  62. package/es/utils.js +0 -621
  63. package/lib/components/NewDateFormat.js +0 -68
  64. package/lib/offset.js +0 -634
  65. package/lib/timezones.js +0 -129
  66. package/lib/utils.js +0 -651
  67. package/src/components/NewDateFormat.js +0 -60
  68. package/src/offset.js +0 -629
  69. package/src/timezones.js +0 -113
  70. package/src/utils.js +0 -648
@@ -0,0 +1,583 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.dayi18n = void 0;
7
+ exports.formatDate = formatDate;
8
+ exports.getDatePatternWithoutYear = getDatePatternWithoutYear;
9
+ exports.getDiffObj = getDiffObj;
10
+ exports.getI18NInfo = getI18NInfo;
11
+ exports.getI18NValue = getI18NValue;
12
+ exports.getLocalizedValue = getLocalizedValue;
13
+ exports.getLyears = getLyears;
14
+ exports.getSuffix = getSuffix;
15
+ exports.getValues = getValues;
16
+ exports.isObject = isObject;
17
+ exports.isToday = isToday;
18
+ exports.isTomorrow = isTomorrow;
19
+ exports.isTwoWeeksOrMore = isTwoWeeksOrMore;
20
+ exports.isWithinAWeek = isWithinAWeek;
21
+ exports.isYesterday = isYesterday;
22
+ exports.monthi18n = void 0;
23
+ exports.pad = pad;
24
+ exports.replaceI18NValuesWithRegex = replaceI18NValuesWithRegex;
25
+ exports.setI18NKeyMapping = setI18NKeyMapping;
26
+ exports.setLocalizedData = setLocalizedData;
27
+ exports.timei18n = void 0;
28
+ exports.unescapeUnicode = unescapeUnicode;
29
+ exports.userDateFormat = userDateFormat;
30
+ var _datetimejs = _interopRequireDefault(require("@zohodesk/datetimejs"));
31
+ var _I18NProvider = require("../components/I18NProvider");
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 = {
39
+ 'Sun': 'deskreact.calendar.daynameshort.sunday',
40
+ 'Mon': 'deskreact.calendar.daynameshort.monday',
41
+ 'Tue': 'deskreact.calendar.daynameshort.tuesday',
42
+ 'Wed': 'deskreact.calendar.daynameshort.wednesday',
43
+ 'Thu': 'deskreact.calendar.daynameshort.thursday',
44
+ 'Fri': 'deskreact.calendar.daynameshort.friday',
45
+ 'Sat': 'deskreact.calendar.daynameshort.saturday',
46
+ 'Sunday': 'deskreact.calendar.dayname.sunday',
47
+ 'Monday': 'deskreact.calendar.dayname.monday',
48
+ 'Tuesday': 'deskreact.calendar.dayname.tuesday',
49
+ 'Wednesday': 'deskreact.calendar.dayname.wednesday',
50
+ 'Thursday': 'deskreact.calendar.dayname.thursday',
51
+ 'Friday': 'deskreact.calendar.dayname.friday',
52
+ 'Saturday': 'deskreact.calendar.dayname.saturday'
53
+ };
54
+ var monthi18n = exports.monthi18n = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
55
+ 'Jan': 'deskreact.calendar.monthnameshort.january',
56
+ 'Feb': 'deskreact.calendar.monthnameshort.february',
57
+ 'Mar': 'deskreact.calendar.monthnameshort.march',
58
+ 'Apr': 'deskreact.calendar.monthnameshort.april',
59
+ 'May': 'deskreact.calendar.monthnameshort.may',
60
+ 'Jun': 'deskreact.calendar.monthnameshort.june',
61
+ 'Jul': 'deskreact.calendar.monthnameshort.july',
62
+ 'Aug': 'deskreact.calendar.monthnameshort.august',
63
+ 'Sep': 'deskreact.calendar.monthnameshort.september',
64
+ 'Oct': 'deskreact.calendar.monthnameshort.october',
65
+ 'Nov': 'deskreact.calendar.monthnameshort.november',
66
+ 'Dec': 'deskreact.calendar.monthnameshort.december',
67
+ 'January': 'deskreact.calendar.monthname.january',
68
+ 'February': 'deskreact.calendar.monthname.february',
69
+ 'March': 'deskreact.calendar.monthname.march',
70
+ 'April': 'deskreact.calendar.monthname.april'
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 = {
73
+ 'a': 'support.time.format.time.am.short.small',
74
+ 'p': 'support.time.format.time.pm.short.small',
75
+ 'am': 'support.time.format.time.am.small',
76
+ 'pm': 'support.time.format.time.pm.small',
77
+ 'A': 'support.time.format.time.am.short',
78
+ 'P': 'support.time.format.time.pm.short',
79
+ 'AM': 'deskreact.calendar.ampmtext.am',
80
+ 'PM': 'deskreact.calendar.ampmtext.pm'
81
+ };
82
+ var dateFormat = {
83
+ dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
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'],
85
+ timeNames: ['a', 'p', 'am', 'pm', 'A', 'P', 'AM', 'PM']
86
+ };
87
+ function formatDate(dateMill, mask, dateDiffObj) {
88
+ if (mask === 'facebookFormat') {
89
+ var hours = dateDiffObj.hours,
90
+ minutes = dateDiffObj.minutes,
91
+ seconds = dateDiffObj.seconds,
92
+ yDays = dateDiffObj.yDays,
93
+ years = dateDiffObj.years,
94
+ betweenleepYears = dateDiffObj.betweenleepYears,
95
+ crntMonth = dateDiffObj.crntMonth;
96
+ if (years > 0) {
97
+ return "".concat(years, "y");
98
+ } else if (yDays > 0) {
99
+ var isFeb = crntMonth === 1;
100
+ var isThoneMonth = [0, 2, 4, 6, 7, 9, 11].indexOf(crntMonth) != -1;
101
+ var weekCal = function weekCal(calDays) {
102
+ var weeks = calDays / 7;
103
+ return weeks < 1 ? "".concat(calDays, "d") : "".concat(Math.trunc(weeks), "w");
104
+ };
105
+ if (!isFeb) {
106
+ return isThoneMonth === true ? yDays === 31 ? '1m' : weekCal(yDays) : yDays === 30 ? '1m' : weekCal(yDays);
107
+ }
108
+ if (betweenleepYears != 0) {
109
+ return isFeb === true && yDays === 28 ? '1m' : weekCal(yDays);
110
+ }
111
+ return isFeb === true && yDays === 29 ? '1m' : weekCal(yDays);
112
+ } else if (hours < 24 && hours > 0) {
113
+ return "".concat(hours, "h");
114
+ } else if (minutes < 60 && hours > 1) {
115
+ return "".concat(minutes, "m");
116
+ }
117
+ return seconds === 0 ? 'now' : "".concat(seconds, "s");
118
+ }
119
+ var date = new Date(dateMill);
120
+ var d = date.getDate();
121
+ var D = date.getDay();
122
+ var m = date.getMonth();
123
+ var y = date.getFullYear();
124
+ var H = date.getHours();
125
+ var M = date.getMinutes();
126
+ var s = date.getSeconds();
127
+ var L = date.getMilliseconds();
128
+ var flags = {
129
+ d: d,
130
+ dd: pad(d, 2),
131
+ ddd: _I18NProvider.i18NProviderUtils.getI18NValue(dayi18n[dateFormat.dayNames[D]]),
132
+ dddd: _I18NProvider.i18NProviderUtils.getI18NValue(dayi18n[dateFormat.dayNames[D + 7]]),
133
+ D: d,
134
+ DD: pad(d, 2),
135
+ DDD: _I18NProvider.i18NProviderUtils.getI18NValue(dayi18n[dateFormat.dayNames[D]]),
136
+ DDDD: _I18NProvider.i18NProviderUtils.getI18NValue(dayi18n[dateFormat.dayNames[D + 7]]),
137
+ M: m + 1,
138
+ MM: pad(m + 1, 2),
139
+ MMM: _I18NProvider.i18NProviderUtils.getI18NValue(monthi18n[dateFormat.monthNames[m]]),
140
+ MMMM: _I18NProvider.i18NProviderUtils.getI18NValue(monthi18n[dateFormat.monthNames[m + 12]]),
141
+ yy: String(y).slice(2),
142
+ YY: String(y).slice(2),
143
+ yyyy: y,
144
+ YYYY: y,
145
+ h: H % 12 || 12,
146
+ hh: pad(H % 12 || 12, 2),
147
+ H: H,
148
+ HH: pad(H, 2),
149
+ m: M,
150
+ mm: pad(M, 2),
151
+ s: s,
152
+ ss: pad(s, 2),
153
+ l: pad(L, 3),
154
+ L: pad(Math.round(L / 10)),
155
+ t: H < 12 ? _I18NProvider.i18NProviderUtils.getI18NValue(timei18n[dateFormat.timeNames[0]]) : _I18NProvider.i18NProviderUtils.getI18NValue(timei18n[dateFormat.timeNames[1]]),
156
+ A: H < 12 ? _I18NProvider.i18NProviderUtils.getI18NValue(timei18n[dateFormat.timeNames[6]]) : _I18NProvider.i18NProviderUtils.getI18NValue(timei18n[dateFormat.timeNames[7]]),
157
+ T: H < 12 ? _I18NProvider.i18NProviderUtils.getI18NValue(timei18n[dateFormat.timeNames[4]]) : _I18NProvider.i18NProviderUtils.getI18NValue(timei18n[dateFormat.timeNames[5]])
158
+ };
159
+ var token = /D{1,4}|M{1,4}|YY(?:YY)?|([HhmsA])\1?|[LloSZWN]|\[[^\]]*\]|'[^']*'/gi;
160
+ var dat = mask.replace(token, function (match) {
161
+ if (match in flags) {
162
+ return flags[match];
163
+ }
164
+ return match.slice(1, match.length - 1);
165
+ });
166
+ return dat;
167
+ }
168
+ function pad(n) {
169
+ var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
170
+ var z = arguments.length > 2 ? arguments[2] : undefined;
171
+ z = z || '0';
172
+ n = "".concat(n);
173
+ return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
174
+ }
175
+ function replaceI18NValuesWithRegex(i18nStr, values) {
176
+ if (typeof values !== 'undefined') {
177
+ if (Array.isArray(values)) {
178
+ for (var i = 0; i < values.length; i++) {
179
+ i18nStr = i18nStr.replace(new RegExp("\\{".concat(i, "\\}"), 'g'), values[i]);
180
+ }
181
+ } else {
182
+ i18nStr = i18nStr.replace(new RegExp('\\{0\\}', 'g'), values);
183
+ }
184
+ }
185
+ return i18nStr;
186
+ }
187
+ function unescapeUnicode(str) {
188
+ return str.replace(/\\u([a-fA-F0-9]{4})/g, function (g, m1) {
189
+ return String.fromCharCode(parseInt(m1, 16));
190
+ });
191
+ }
192
+ function getValues() {
193
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
194
+ var diff = arguments.length > 1 ? arguments[1] : undefined;
195
+ return params.map(function (param) {
196
+ return diff[param];
197
+ });
198
+ }
199
+ function isObject(item) {
200
+ return item && _typeof(item) === 'object' && !Array.isArray(item);
201
+ }
202
+ var localizedData = {};
203
+ var localizedStringData = {};
204
+ var getMappedKey = function getMappedKey(key) {
205
+ return key;
206
+ };
207
+ function setLocalizedStringData(data) {
208
+ var keyString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
209
+ if (typeof data === 'string') {
210
+ localizedStringData[keyString] = data;
211
+ return;
212
+ }
213
+ var keys = Object.keys(data);
214
+ for (var i = 0; i < keys.length; i++) {
215
+ var _key = keys[i];
216
+ var newKeyString = keyString ? "".concat(keyString, ".").concat(_key) : _key;
217
+ setLocalizedStringData(data[_key], newKeyString);
218
+ }
219
+ }
220
+ function setLocalizedData(data) {
221
+ var translationData = isObject(data) ? data : {};
222
+ localizedData = translationData;
223
+ setLocalizedStringData(translationData);
224
+ }
225
+ function setI18NKeyMapping(func) {
226
+ getMappedKey = func;
227
+ }
228
+ function getLocalizedValue() {
229
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
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;
239
+ var localizedValue = localizedData;
240
+ switch (type) {
241
+ case 'field':
242
+ ['Field', moduleName, apiName].map(function (key) {
243
+ localizedValue = localizedValue[key] || '';
244
+ });
245
+ break;
246
+ case 'picklist':
247
+ ['PickListValue', moduleName, apiName, fieldValue].map(function (key) {
248
+ localizedValue = localizedValue[key] || '';
249
+ });
250
+ break;
251
+ case 'layout':
252
+ if (deptName != null) {
253
+ ['Layout', moduleName, deptName, layoutName].map(function () {
254
+ localizedValue = localizedValue[key] || '';
255
+ });
256
+ } else {
257
+ ['Layout', moduleName, layoutName].map(function () {
258
+ localizedValue = localizedValue[key] || '';
259
+ });
260
+ }
261
+ break;
262
+ case 'report':
263
+ ['Report', deptName, folderName, reportName, reportId].map(function (key) {
264
+ localizedValue = localizedValue[key] || '';
265
+ });
266
+ default:
267
+ return null;
268
+ }
269
+ return localizedValue || null;
270
+ }
271
+ function getI18NValue(i18n) {
272
+ if (typeof i18n === 'undefined') {
273
+ (0, _errorReporter.reportI18NError)(_errorReporter.I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object');
274
+ return function (key) {
275
+ return key;
276
+ };
277
+ }
278
+ return function (key, values, localizedProps) {
279
+ var localizedValue = localizedProps ? getLocalizedValue(localizedProps) : localizedStringData[key];
280
+ var finalKey = getMappedKey(key);
281
+ var i18nStr = i18n[finalKey];
282
+ if (i18nStr === undefined) {
283
+ var isNumeric = /^\d+$/.test(finalKey);
284
+ var errorType = isNumeric ? _errorReporter.I18N_ERROR_TYPES.NUMERIC_FALLBACK : _errorReporter.I18N_ERROR_TYPES.MISSING_KEY;
285
+ (0, _errorReporter.reportI18NError)(errorType, finalKey);
286
+ return localizedValue || (0, _errorReporter.getFallbackText)(finalKey);
287
+ }
288
+ i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
289
+ return localizedValue || unescapeUnicode(i18nStr);
290
+ };
291
+ }
292
+
293
+ // function getValues(params = [], diff) {
294
+ // return params.map(param => {
295
+ // return diff[param];
296
+ // });
297
+ // }
298
+ function getI18NInfo(toDateObj, props, diffObj) {
299
+ var key = null,
300
+ values,
301
+ text = null;
302
+ if (typeof props === 'function') {
303
+ var value = props(diffObj1);
304
+ key = value.key;
305
+ values = getValues(value.params, diffObj);
306
+ } else if (_typeof(props) === 'object') {
307
+ key = props.key;
308
+ values = getValues(props.params, diffObj);
309
+ } else if (typeof props === 'string') {
310
+ text = toDateObj.format(props);
311
+ }
312
+ return {
313
+ key: key,
314
+ values: values,
315
+ text: text
316
+ };
317
+ }
318
+ function isToday(fromDate, toDate) {
319
+ var TODAY = toDate.clone().startOf('day');
320
+ return fromDate.isSame(TODAY, 'd');
321
+ }
322
+ function isYesterday(fromDate, toDate) {
323
+ var YESTERDAY = toDate.clone().subtract(1, 'days').startOf('day');
324
+ return fromDate.isSame(YESTERDAY, 'd');
325
+ }
326
+ function isTomorrow(fromDate, toDate) {
327
+ return isYesterday(toDate, fromDate);
328
+ }
329
+ function isWithinAWeek(fromDate, toDate) {
330
+ var A_WEEK_OLD = toDate.clone().subtract(7, 'days').startOf('day');
331
+ return fromDate.isAfter(A_WEEK_OLD);
332
+ }
333
+ function isTwoWeeksOrMore(fromDate, toDate) {
334
+ return !isWithinAWeek(fromDate, toDate);
335
+ }
336
+ function getDatePatternWithoutYear(datePattern) {
337
+ var dateObj;
338
+ var delemiter;
339
+ if (datePattern.indexOf('.') !== -1) {
340
+ dateObj = datePattern.split('.');
341
+ delemiter = '.';
342
+ } else if (datePattern.indexOf('-') !== -1) {
343
+ dateObj = datePattern.split('-');
344
+ delemiter = '-';
345
+ } else if (datePattern.indexOf('/') !== -1) {
346
+ dateObj = datePattern.split('/');
347
+ delemiter = '/';
348
+ } else {
349
+ dateObj = datePattern.split(' ');
350
+ delemiter = ' ';
351
+ }
352
+ return dateObj.filter(function (data) {
353
+ return ['yy', 'yyyy'].indexOf(data) === -1;
354
+ }).join(delemiter);
355
+ }
356
+ function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isEnabledCurrentYear) {
357
+ return function (to, _ref2, ago, later) {
358
+ var today = _ref2.today,
359
+ yesterday = _ref2.yesterday,
360
+ tomorrow = _ref2.tomorrow,
361
+ others = _ref2.others;
362
+ var isSuffixEnable = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
363
+ var format = arguments.length > 5 ? arguments[5] : undefined;
364
+ var fromDateObj = _datetimejs["default"].toDate(_datetimejs["default"].tz.utcToTz(null, timezoneData));
365
+ var toDateObj = _datetimejs["default"].toDate(_datetimejs["default"].tz.utcToTz(to, timezoneData));
366
+ var diffMin = new Date(to).getTime() - new Date().getTime();
367
+ var from = new Date();
368
+ from = from.toISOString();
369
+ var suffix;
370
+ if (diffMin < 0) {
371
+ suffix = ago || '';
372
+ } else if (diffMin > 0) {
373
+ suffix = later || '';
374
+ } else {
375
+ suffix = '';
376
+ }
377
+ var diff = getDiffObj(diffMin);
378
+ var withInAWeak = diff.y === 0 && diff.yd <= 7;
379
+ var diffObj = {
380
+ h: diff.h,
381
+ m: diff.m,
382
+ s: diff.s,
383
+ y: diff.y,
384
+ hh: pad(diff.h, 2),
385
+ mm: pad(diff.m, 2),
386
+ ss: pad(diff.s, 2),
387
+ yy: pad(diff.y, 2),
388
+ days: diff.yd,
389
+ yDays: pad(diff.yd, 2),
390
+ isWithInAWeek: withInAWeak,
391
+ suffix: suffix
392
+ };
393
+ var diffObj1 = {
394
+ hours: diff.h,
395
+ minutes: diff.m,
396
+ seconds: diff.s,
397
+ years: diff.y,
398
+ yDays: diff.yd,
399
+ crntYear: new Date(from).getFullYear(),
400
+ tYear: new Date(to).getFullYear(),
401
+ isWithInAWeek: withInAWeak,
402
+ suffix: suffix,
403
+ timeFormat: timeFormat,
404
+ datePattern: datePattern,
405
+ dateTimePattern: "".concat(datePattern, " ").concat(timeFormat)
406
+ };
407
+
408
+ //In if condition we'll remove year and set date format if the current year is not required
409
+ //In else part we'll set the date format as it is
410
+ if (isEnabledCurrentYear === true && diffObj1.years === 0 && diffObj1.tYear === diffObj1.crntYear) {
411
+ var _dateFormat = getDatePatternWithoutYear(datePattern);
412
+ diffObj1.dateFormat = _dateFormat;
413
+ diffObj1.dateTimeFormat = "".concat(_dateFormat, " ").concat(timeFormat);
414
+ } else {
415
+ diffObj1.dateFormat = datePattern;
416
+ diffObj1.dateTimeFormat = "".concat(datePattern, " ").concat(timeFormat);
417
+ }
418
+
419
+ //var daysDiff = toDateObj.diff(fromDateObj, 'days');
420
+
421
+ var key = '';
422
+ var values = [];
423
+ var text = null;
424
+ if (format) {
425
+ var years, months, days, hours, minutes, seconds;
426
+ years = diffObj1.years > 1 ? '2' : diffObj1.years;
427
+ // months = diffObj1.months > 1 ? '2' : diffObj1.months;
428
+ // days = diffObj1.days > 1 ? '2' : diffObj1.days;
429
+ days = diff.yd > 1 ? '2' : diff.yd;
430
+ hours = diffObj1.hours > 1 ? '2' : diffObj1.hours;
431
+ minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes;
432
+ //seconds = diffObj1.seconds > 1 ? '2' : diffObj1.seconds;
433
+ // let pattern = '' + years + months + days + hours + minutes + seconds;
434
+ var count = 0;
435
+ var pattern = [years, days, hours, minutes].reduce(function (res, next) {
436
+ if (count === 2 || next === 0) {
437
+ res = "".concat(res, "0");
438
+ } else if (next !== 0) {
439
+ count++;
440
+ res = res + next;
441
+ } else {
442
+ res = res + next;
443
+ }
444
+ return res;
445
+ }, '');
446
+ var value = format(diffObj1, pattern);
447
+ if (value && _typeof(value) === 'object') {
448
+ key = value.key;
449
+ values = getValues(value.params, diffObj);
450
+ isSuffixEnable = true;
451
+ } else if (typeof value === 'string') {
452
+ text = formatDate(toDateObj, value);
453
+ }
454
+ } else {
455
+ var dateObj = new Date(toDateObj);
456
+ var curDateObj = new Date(fromDateObj);
457
+ var diffDayType = diffObj1.yDays;
458
+
459
+ //In this condition, to calculate different days we have copied it from live --> diffDayType
460
+ if (isOverdue && dateObj.getDate() < curDateObj.getDate() && diffObj1.yDays == 0) {
461
+ diffDayType = -1;
462
+ }
463
+ if (!isOverdue) {
464
+ var diffHr = dateObj.getHours() - curDateObj.getHours();
465
+ if (diffHr < 0) {
466
+ diffDayType += 1;
467
+ } else if (diffHr == 0) {
468
+ var diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
469
+ if (diffMins < 0) {
470
+ diffDayType += 1;
471
+ } else if (diffMins == 0) {
472
+ var diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
473
+ if (diffSec < 0) {
474
+ diffDayType += 1;
475
+ }
476
+ }
477
+ }
478
+ }
479
+ if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
480
+ if (today && dateObj.getDate() === curDateObj.getDate()) {
481
+ if (_typeof(today) === 'object') {
482
+ key = today.key;
483
+ values = getValues(today.params, diffObj);
484
+ isSuffixEnable = true;
485
+ } else if (typeof today === 'string') {
486
+ text = formatDate(toDateObj, today);
487
+ }
488
+ } else if (yesterday && dateObj.getMonth() === curDateObj.getMonth() && dateObj.getDate() < curDateObj.getDate() || yesterday && dateObj.getMonth() < curDateObj.getMonth()) {
489
+ if (_typeof(yesterday) === 'object') {
490
+ key = yesterday.key;
491
+ values = getValues(yesterday.params, diffObj);
492
+ } else if (typeof yesterday === 'string') {
493
+ text = formatDate(toDateObj, yesterday);
494
+ }
495
+ } else if (tomorrow && !isOverdue && diff.y === 0 && diffDayType === 1) {
496
+ if (_typeof(tomorrow) === 'object') {
497
+ key = tomorrow.key;
498
+ values = getValues(tomorrow.params, diffObj);
499
+ } else if (typeof tomorrow === 'string') {
500
+ text = formatDate(toDateObj, tomorrow);
501
+ }
502
+ } else {
503
+ var _value = others(diffObj1);
504
+ if (_typeof(_value) === 'object') {
505
+ key = _value.key;
506
+ values = getValues(_value.params, diffObj);
507
+ isSuffixEnable = true;
508
+ } else if (typeof _value === 'string') {
509
+ text = formatDate(toDateObj, _value);
510
+ }
511
+ }
512
+ } else {
513
+ var _value2 = others(diffObj1);
514
+ if (_typeof(_value2) === 'object') {
515
+ key = _value2.key;
516
+ values = getValues(_value2.params, diffObj);
517
+ isSuffixEnable = true;
518
+ } else if (typeof _value2 === 'string') {
519
+ text = formatDate(toDateObj, _value2);
520
+ }
521
+ }
522
+ }
523
+ var key1 = isSuffixEnable && suffix != '' ? "".concat(key, ".").concat(suffix) : key;
524
+ return text || getI18NValue(key1, values);
525
+ };
526
+ }
527
+ var oneYearInMillis = 31536000000;
528
+ var oneDayInMillis = 86400000;
529
+ var oneHourInMillis = 3600000;
530
+ var oneMinuteInMillis = 60000;
531
+ function convertAsNonExponential(number) {
532
+ if (number.toString().toLowerCase().indexOf('e') !== -1) {
533
+ return number.toFixed(20);
534
+ }
535
+ return number;
536
+ }
537
+ function getDiffObj(diff) {
538
+ diff = Math.abs(diff);
539
+ var diffYears = diff / oneYearInMillis;
540
+ diffYears = convertAsNonExponential(diffYears);
541
+ var diffDays = diff % oneYearInMillis / oneDayInMillis;
542
+ diffDays = convertAsNonExponential(diffDays);
543
+ var diffHours = diff % oneDayInMillis / oneHourInMillis;
544
+ diffHours = convertAsNonExponential(diffHours);
545
+ var diffMinutes = diff % oneDayInMillis % oneHourInMillis / oneMinuteInMillis;
546
+ var diffSeconds = diff % oneDayInMillis % oneHourInMillis % oneMinuteInMillis / 1000;
547
+ diffDays = parseInt(diffDays);
548
+ diffHours = parseInt(diffHours);
549
+ diffMinutes = parseInt(diffMinutes);
550
+ diffSeconds = parseInt(diffSeconds);
551
+ diffYears = parseInt(diffYears);
552
+ return {
553
+ y: diffYears,
554
+ yd: diffDays,
555
+ h: diffHours,
556
+ m: diffMinutes,
557
+ s: diffSeconds
558
+ };
559
+ }
560
+ function getLyears(from, to) {
561
+ var dFrom = new Date(from),
562
+ dTo = new Date(to);
563
+ var fromYear = dFrom.getFullYear();
564
+ var toYear = dTo.getFullYear();
565
+ var arrayofLeapYears = [];
566
+ for (var loopYear = fromYear; loopYear <= toYear; loopYear++) {
567
+ if (loopYear % 4 === 0 && loopYear % 100 !== 0 || loopYear % 100 === 0 && loopYear % 400 === 0) {
568
+ arrayofLeapYears.push(loopYear);
569
+ }
570
+ }
571
+ return arrayofLeapYears.length;
572
+ }
573
+ function getSuffix(min, ago, later) {
574
+ var suffix;
575
+ if (min < 0) {
576
+ suffix = ago || '';
577
+ } else if (min > 0) {
578
+ suffix = later || '';
579
+ } else {
580
+ suffix = '';
581
+ }
582
+ return suffix;
583
+ }