@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.
- package/README.md +73 -41
- package/es/components/DateTimeDiffFormat.js +46 -12
- package/es/components/HOCI18N.js +33 -30
- package/es/components/I18NProvider.js +7 -16
- package/es/components/UserTimeDiffFormat.js +11 -9
- package/es/components/__tests__/DateTimeDiffFormat.spec.js +177 -136
- package/es/components/__tests__/FormatText.spec.js +0 -1
- package/es/components/__tests__/HOCI18N.spec.js +0 -1
- package/es/components/__tests__/I18N.spec.js +0 -2
- package/es/components/__tests__/I18NProvider.spec.js +0 -1
- package/es/components/__tests__/PluralFormat.spec.js +0 -1
- package/es/components/__tests__/UserTimeDiffFormat.spec.js +287 -206
- package/es/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/es/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/es/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/es/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/es/index.js +2 -3
- package/es/utils.js +119 -171
- package/lib/components/DateTimeDiffFormat.js +49 -15
- package/lib/components/FormatText.js +4 -4
- package/lib/components/HOCI18N.js +4 -4
- package/lib/components/I18N.js +4 -4
- package/lib/components/I18NProvider.js +12 -21
- package/lib/components/PluralFormat.js +4 -4
- package/lib/components/UserTimeDiffFormat.js +12 -14
- package/lib/components/__tests__/I18NProvider.spec.js +1 -1
- package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1 -1
- package/lib/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/lib/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/lib/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/lib/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/lib/index.js +54 -56
- package/lib/utils.js +130 -212
- package/package.json +28 -28
- package/src/I18NContext.js +2 -2
- package/src/components/DateTimeDiffFormat.js +254 -211
- package/src/components/FormatText.js +14 -14
- package/src/components/HOCI18N.js +37 -37
- package/src/components/I18N.js +72 -72
- package/src/components/I18NProvider.js +106 -116
- package/src/components/PluralFormat.js +37 -37
- package/src/components/UserTimeDiffFormat.js +94 -103
- package/src/components/__tests__/DateTimeDiffFormat.spec.js +618 -618
- package/src/components/__tests__/FormatText.spec.js +26 -26
- package/src/components/__tests__/HOCI18N.spec.js +33 -33
- package/src/components/__tests__/I18N.spec.js +29 -29
- package/src/components/__tests__/I18NProvider.spec.js +65 -65
- package/src/components/__tests__/PluralFormat.spec.js +27 -27
- package/src/components/__tests__/UserTimeDiffFormat.spec.js +1076 -1076
- package/src/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/src/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/src/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/src/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/src/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/src/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/src/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/src/index.js +33 -33
- package/src/utils.js +527 -587
- package/es/components/NewDateFormat.js +0 -53
- package/lib/components/NewDateFormat.js +0 -60
- package/src/components/NewDateFormat.js +0 -60
package/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { formatDate, pad, replaceI18NValuesWithRegex, unescapeUnicode, getValues, getI18NInfo, isToday, isYesterday, isTomorrow, isWithinAWeek, isTwoWeeksOrMore, userDateFormat, getDiffObj, getLyears, getSuffix,
|
|
1
|
+
export { formatDate, pad, replaceI18NValuesWithRegex, unescapeUnicode, getValues, getI18NInfo, isToday, isYesterday, isTomorrow, isWithinAWeek, isTwoWeeksOrMore, userDateFormat, getDiffObj, getLyears, getSuffix, getDatePatternWithoutYear, setLocalizedData } from './utils';
|
|
2
2
|
import { getI18NValue as getI18NValue1 } from './utils';
|
|
3
3
|
export { I18NContext } from './I18NContext';
|
|
4
4
|
export { default as I18NProvider, i18NProviderUtils } from './components/I18NProvider';
|
|
@@ -8,5 +8,4 @@ export { default as FormatText } from './components/FormatText';
|
|
|
8
8
|
export { default as PluralFormat } from './components/PluralFormat';
|
|
9
9
|
export { default as DateTimeDiffFormat } from './components/DateTimeDiffFormat';
|
|
10
10
|
export { default as UserTimeDiffFormat } from './components/UserTimeDiffFormat';
|
|
11
|
-
export const getI18NValue = (i18n, key, values) => getI18NValue1(i18n)(key, values);
|
|
12
|
-
export { default as NewDateFormat } from './components/NewDateFormat';
|
|
11
|
+
export const getI18NValue = (i18n, key, values) => getI18NValue1(i18n)(key, values);
|
package/es/utils.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "core-js/modules/es.string.replace";
|
|
2
1
|
import datetime from '@zohodesk/datetimejs';
|
|
3
2
|
let dateFormat = {
|
|
4
3
|
dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
|
@@ -96,7 +95,9 @@ export function formatDate(dateMill, mask, dateDiffObj) {
|
|
|
96
95
|
});
|
|
97
96
|
return dat;
|
|
98
97
|
}
|
|
99
|
-
export function pad(n
|
|
98
|
+
export function pad(n) {
|
|
99
|
+
let width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
100
|
+
let z = arguments.length > 2 ? arguments[2] : undefined;
|
|
100
101
|
z = z || '0';
|
|
101
102
|
n = `${n}`;
|
|
102
103
|
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
|
|
@@ -117,23 +118,58 @@ export function replaceI18NValuesWithRegex(i18nStr, values) {
|
|
|
117
118
|
export function unescapeUnicode(str) {
|
|
118
119
|
return str.replace(/\\u([a-fA-F0-9]{4})/g, (g, m1) => String.fromCharCode(parseInt(m1, 16)));
|
|
119
120
|
}
|
|
120
|
-
export function getValues(
|
|
121
|
+
export function getValues() {
|
|
122
|
+
let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
123
|
+
let diff = arguments.length > 1 ? arguments[1] : undefined;
|
|
121
124
|
return params.map(param => diff[param]);
|
|
122
125
|
}
|
|
126
|
+
let localizedData = {};
|
|
127
|
+
export function setLocalizedData(data) {
|
|
128
|
+
localizedData = data;
|
|
129
|
+
}
|
|
130
|
+
export function getLocalizedValue() {
|
|
131
|
+
let {
|
|
132
|
+
type,
|
|
133
|
+
moduleName,
|
|
134
|
+
apiName,
|
|
135
|
+
fieldValue
|
|
136
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
137
|
+
let localizedValue = localizedData;
|
|
138
|
+
|
|
139
|
+
switch (type) {
|
|
140
|
+
case 'field':
|
|
141
|
+
['Field', moduleName, apiName].map(key => {
|
|
142
|
+
localizedValue = localizedValue[key] || '';
|
|
143
|
+
});
|
|
144
|
+
break;
|
|
145
|
+
|
|
146
|
+
case 'picklist':
|
|
147
|
+
['PickListValue', moduleName, apiName, fieldValue].map(key => {
|
|
148
|
+
localizedValue = localizedValue[key] || '';
|
|
149
|
+
});
|
|
150
|
+
break;
|
|
151
|
+
|
|
152
|
+
default:
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return localizedValue || null;
|
|
157
|
+
}
|
|
123
158
|
export function getI18NValue(i18n) {
|
|
124
159
|
if (typeof i18n === 'undefined') {
|
|
125
160
|
return key => key;
|
|
126
161
|
}
|
|
127
162
|
|
|
128
|
-
return (key, values) => {
|
|
163
|
+
return (key, values, localizedProps) => {
|
|
164
|
+
const localizedValue = localizedProps ? getLocalizedValue(localizedProps) : null;
|
|
129
165
|
let i18nStr = i18n[key];
|
|
130
166
|
|
|
131
167
|
if (i18nStr === undefined) {
|
|
132
|
-
return key;
|
|
168
|
+
return localizedValue || key;
|
|
133
169
|
}
|
|
134
170
|
|
|
135
171
|
i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
|
|
136
|
-
return unescapeUnicode(i18nStr);
|
|
172
|
+
return localizedValue || unescapeUnicode(i18nStr);
|
|
137
173
|
};
|
|
138
174
|
} // function getValues(params = [], diff) {
|
|
139
175
|
// return params.map(param => {
|
|
@@ -181,16 +217,41 @@ export function isWithinAWeek(fromDate, toDate) {
|
|
|
181
217
|
export function isTwoWeeksOrMore(fromDate, toDate) {
|
|
182
218
|
return !isWithinAWeek(fromDate, toDate);
|
|
183
219
|
}
|
|
184
|
-
export function
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
220
|
+
export function getDatePatternWithoutYear(datePattern) {
|
|
221
|
+
let dateObj;
|
|
222
|
+
let delemiter;
|
|
223
|
+
|
|
224
|
+
if (datePattern.indexOf('.') !== -1) {
|
|
225
|
+
dateObj = datePattern.split('.');
|
|
226
|
+
delemiter = '.';
|
|
227
|
+
} else if (datePattern.indexOf('-') !== -1) {
|
|
228
|
+
dateObj = datePattern.split('-');
|
|
229
|
+
delemiter = '-';
|
|
230
|
+
} else if (datePattern.indexOf('/') !== -1) {
|
|
231
|
+
dateObj = datePattern.split('/');
|
|
232
|
+
delemiter = '/';
|
|
233
|
+
} else {
|
|
234
|
+
dateObj = datePattern.split(' ');
|
|
235
|
+
delemiter = ' ';
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return dateObj.filter(data => ['yy', 'yyyy'].indexOf(data) === -1).join(delemiter);
|
|
239
|
+
}
|
|
240
|
+
export function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isEnabledCurrentYear) {
|
|
241
|
+
return function (to, _ref, ago, later) {
|
|
242
|
+
let {
|
|
243
|
+
today,
|
|
244
|
+
yesterday,
|
|
245
|
+
tomorrow,
|
|
246
|
+
others
|
|
247
|
+
} = _ref;
|
|
248
|
+
let isSuffixEnable = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
249
|
+
let format = arguments.length > 5 ? arguments[5] : undefined;
|
|
191
250
|
let fromDateObj = datetime.toDate(datetime.tz.utcToTz(null, timezoneData));
|
|
192
251
|
let toDateObj = datetime.toDate(datetime.tz.utcToTz(to, timezoneData));
|
|
193
252
|
let diffMin = new Date(to).getTime() - new Date().getTime();
|
|
253
|
+
let from = new Date();
|
|
254
|
+
from = from.toISOString();
|
|
194
255
|
let suffix;
|
|
195
256
|
|
|
196
257
|
if (diffMin < 0) {
|
|
@@ -223,12 +284,25 @@ export function userDateFormat(getI18NValue, timezoneData, timeFormat, defaulDat
|
|
|
223
284
|
seconds: diff.s,
|
|
224
285
|
years: diff.y,
|
|
225
286
|
yDays: diff.yd,
|
|
287
|
+
crntYear: new Date(from).getFullYear(),
|
|
288
|
+
tYear: new Date(to).getFullYear(),
|
|
226
289
|
isWithInAWeek: withInAWeak,
|
|
227
290
|
suffix: suffix,
|
|
228
291
|
timeFormat: timeFormat,
|
|
229
|
-
datePattern:
|
|
230
|
-
|
|
231
|
-
}; //
|
|
292
|
+
datePattern: datePattern,
|
|
293
|
+
dateTimePattern: `${datePattern} ${timeFormat}`
|
|
294
|
+
}; //In if condition we'll remove year and set date format if the current year is not required
|
|
295
|
+
//In else part we'll set the date format as it is
|
|
296
|
+
|
|
297
|
+
if (isEnabledCurrentYear === true && diffObj1.years === 0 && diffObj1.tYear === diffObj1.crntYear) {
|
|
298
|
+
let dateFormat = getDatePatternWithoutYear(datePattern);
|
|
299
|
+
diffObj1.dateFormat = dateFormat;
|
|
300
|
+
diffObj1.dateTimeFormat = `${dateFormat} ${timeFormat}`;
|
|
301
|
+
} else {
|
|
302
|
+
diffObj1.dateFormat = datePattern;
|
|
303
|
+
diffObj1.dateTimeFormat = `${datePattern} ${timeFormat}`;
|
|
304
|
+
} //var daysDiff = toDateObj.diff(fromDateObj, 'days');
|
|
305
|
+
|
|
232
306
|
|
|
233
307
|
let key = '';
|
|
234
308
|
let values = [];
|
|
@@ -267,10 +341,35 @@ export function userDateFormat(getI18NValue, timezoneData, timeFormat, defaulDat
|
|
|
267
341
|
text = formatDate(toDateObj, value);
|
|
268
342
|
}
|
|
269
343
|
} else {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
344
|
+
let dateObj = new Date(toDateObj);
|
|
345
|
+
let curDateObj = new Date(fromDateObj);
|
|
346
|
+
let diffDayType = diffObj1.yDays; //In this condition, to calculate different days we have copied it from live --> diffDayType
|
|
273
347
|
|
|
348
|
+
if (isOverdue && dateObj.getDate() < curDateObj.getDate() && diffObj1.yDays == 0) {
|
|
349
|
+
diffDayType = -1;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (!isOverdue) {
|
|
353
|
+
let diffHr = dateObj.getHours() - curDateObj.getHours();
|
|
354
|
+
|
|
355
|
+
if (diffHr < 0) {
|
|
356
|
+
diffDayType += 1;
|
|
357
|
+
} else if (diffHr == 0) {
|
|
358
|
+
let diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
|
|
359
|
+
|
|
360
|
+
if (diffMins < 0) {
|
|
361
|
+
diffDayType += 1;
|
|
362
|
+
} else if (diffMins == 0) {
|
|
363
|
+
let diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
|
|
364
|
+
|
|
365
|
+
if (diffSec < 0) {
|
|
366
|
+
diffDayType += 1;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
|
|
274
373
|
if (today && dateObj.getDate() === curDateObj.getDate()) {
|
|
275
374
|
if (typeof today === 'object') {
|
|
276
375
|
key = today.key;
|
|
@@ -286,7 +385,7 @@ export function userDateFormat(getI18NValue, timezoneData, timeFormat, defaulDat
|
|
|
286
385
|
} else if (typeof yesterday === 'string') {
|
|
287
386
|
text = formatDate(toDateObj, yesterday);
|
|
288
387
|
}
|
|
289
|
-
} else if (tomorrow &&
|
|
388
|
+
} else if (tomorrow && !isOverdue && diff.y === 0 && diffDayType === 1) {
|
|
290
389
|
if (typeof tomorrow === 'object') {
|
|
291
390
|
key = tomorrow.key;
|
|
292
391
|
values = getValues(tomorrow.params, diffObj);
|
|
@@ -384,155 +483,4 @@ export function getSuffix(min, ago, later) {
|
|
|
384
483
|
}
|
|
385
484
|
|
|
386
485
|
return suffix;
|
|
387
|
-
}
|
|
388
|
-
export function getFormatedDate(to, today, yesterday, tomorrow, others, ago, later, format, titleFormat, titleString, calculateFrom, timezoneData) {
|
|
389
|
-
let fromDateObj = datetime.toDate(datetime.tz.utcToTz(calculateFrom, timezoneData));
|
|
390
|
-
let toDateObj = datetime.toDate(datetime.tz.utcToTz(to, timezoneData));
|
|
391
|
-
let diffMin = new Date(to).getTime() - new Date(calculateFrom).getTime();
|
|
392
|
-
let suffix = getSuffix(diffMin, ago, later);
|
|
393
|
-
let diff = getDiffObj(diffMin);
|
|
394
|
-
let withInAWeak = diff.y === 0 && diff.yd <= 7;
|
|
395
|
-
let diffObj = {
|
|
396
|
-
h: diff.h,
|
|
397
|
-
m: diff.m,
|
|
398
|
-
s: diff.s,
|
|
399
|
-
y: diff.y,
|
|
400
|
-
hh: pad(diff.h, 2),
|
|
401
|
-
mm: pad(diff.m, 2),
|
|
402
|
-
ss: pad(diff.s, 2),
|
|
403
|
-
yy: pad(diff.y, 2),
|
|
404
|
-
days: diff.yd,
|
|
405
|
-
yDays: pad(diff.yd, 2),
|
|
406
|
-
isWithInAWeek: withInAWeak,
|
|
407
|
-
suffix: suffix
|
|
408
|
-
};
|
|
409
|
-
let diffObj1 = {
|
|
410
|
-
hours: diff.h,
|
|
411
|
-
minutes: diff.m,
|
|
412
|
-
seconds: diff.s,
|
|
413
|
-
years: diff.y,
|
|
414
|
-
yDays: diff.yd,
|
|
415
|
-
isWithInAWeek: withInAWeak,
|
|
416
|
-
suffix: suffix,
|
|
417
|
-
crntMonth: new Date(to).getMonth(),
|
|
418
|
-
betweenleepYears: getLyears(calculateFrom, to)
|
|
419
|
-
}; //var daysDiff = toDateObj.diff(fromDateObj, 'days', true);
|
|
420
|
-
|
|
421
|
-
let key = '';
|
|
422
|
-
let values = [];
|
|
423
|
-
let text = null;
|
|
424
|
-
let isSuffixEnable = false;
|
|
425
|
-
|
|
426
|
-
if (format) {
|
|
427
|
-
let years, months, days, hours, minutes, seconds;
|
|
428
|
-
years = diffObj1.years > 1 ? '2' : diffObj1.years; // months = diffObj1.months > 1 ? '2' : diffObj1.months;
|
|
429
|
-
//days = diffObj1.days > 1 ? '2' : diffObj1.days;
|
|
430
|
-
|
|
431
|
-
days = diff.yd > 1 ? '2' : diff.yd;
|
|
432
|
-
hours = diffObj1.hours > 1 ? '2' : diffObj1.hours;
|
|
433
|
-
minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes; //seconds = diffObj1.seconds > 1 ? '2' : diffObj1.seconds;
|
|
434
|
-
// let pattern = '' + years + months + days + hours + minutes + seconds;
|
|
435
|
-
|
|
436
|
-
let count = 0;
|
|
437
|
-
let pattern = [years, days, hours, minutes].reduce((res, next) => {
|
|
438
|
-
if (count === 2) {
|
|
439
|
-
res = `${res}0`;
|
|
440
|
-
} else if (next !== 0) {
|
|
441
|
-
count++;
|
|
442
|
-
res = res + next;
|
|
443
|
-
} else {
|
|
444
|
-
res = res + next;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
return res;
|
|
448
|
-
}, ''); //let pattern = '' + years + days + hours + minutes;
|
|
449
|
-
|
|
450
|
-
let value = format(diffObj1, pattern);
|
|
451
|
-
|
|
452
|
-
if (value && typeof value === 'object') {
|
|
453
|
-
key = value.key;
|
|
454
|
-
values = getValues(value.params, diffObj);
|
|
455
|
-
|
|
456
|
-
if (pattern.indexOf('00000') === 0) {
|
|
457
|
-
//suffix ignore for second hook
|
|
458
|
-
isSuffixEnable = false;
|
|
459
|
-
} else {
|
|
460
|
-
isSuffixEnable = true;
|
|
461
|
-
}
|
|
462
|
-
} else if (typeof value === 'string') {
|
|
463
|
-
if (value === 'socialFormat') {
|
|
464
|
-
let defaultRelativeTime = {
|
|
465
|
-
future: t => `in ${t}`,
|
|
466
|
-
past: t => `${t} ago`,
|
|
467
|
-
present: () => 'just now',
|
|
468
|
-
s: () => 'a few seconds ago',
|
|
469
|
-
ss: t => `${t} seconds ago`,
|
|
470
|
-
m: () => 'a minute ago',
|
|
471
|
-
mm: t => `${t} minutes ago`,
|
|
472
|
-
h: () => 'an hour ago',
|
|
473
|
-
hh: t => `${t} hours ago`,
|
|
474
|
-
d: () => 'a day ago',
|
|
475
|
-
dd: t => `${t} days ago`,
|
|
476
|
-
M: () => 'a month ago',
|
|
477
|
-
MM: t => `${t} months ago`,
|
|
478
|
-
y: () => 'a year ago',
|
|
479
|
-
yy: t => `${t} years ago`
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
if (diff.yd === 0) {
|
|
483
|
-
if (diffObj.h < 1) {
|
|
484
|
-
if (diffObj.m < 1) {
|
|
485
|
-
if (diffObj.s < 1) {
|
|
486
|
-
text = defaultRelativeTime.present();
|
|
487
|
-
} else if (diffObj.s === 1) {
|
|
488
|
-
text = defaultRelativeTime.s();
|
|
489
|
-
} else {
|
|
490
|
-
text = defaultRelativeTime.ss(diffObj.s);
|
|
491
|
-
}
|
|
492
|
-
} else if (diffObj.m === 1) {
|
|
493
|
-
text = defaultRelativeTime.m();
|
|
494
|
-
} else {
|
|
495
|
-
text = defaultRelativeTime.mm(diffObj.mm);
|
|
496
|
-
}
|
|
497
|
-
} else if (diffObj.h === 1) {
|
|
498
|
-
text = defaultRelativeTime.h();
|
|
499
|
-
} else {
|
|
500
|
-
text = defaultRelativeTime.hh(diffObj.h);
|
|
501
|
-
}
|
|
502
|
-
} else {
|
|
503
|
-
text = formatDate(toDateObj, 'DD MMM YYYY', diffObj1);
|
|
504
|
-
}
|
|
505
|
-
} else {
|
|
506
|
-
text = formatDate(toDateObj, value, diffObj1);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
} else {
|
|
510
|
-
if (diff.y === 0 && (diff.yd === 0 || diff.yd === 1)) {
|
|
511
|
-
let dateObj = new Date(toDateObj);
|
|
512
|
-
let curDateObj = new Date(fromDateObj);
|
|
513
|
-
|
|
514
|
-
if (dateObj.getDate() === curDateObj.getDate()) {
|
|
515
|
-
var value = today(diffObj1);
|
|
516
|
-
text = formatDate(toDateObj, today);
|
|
517
|
-
} else if (dateObj.getMonth() < curDateObj.getMonth() || dateObj.getDate() < curDateObj.getDate()) {
|
|
518
|
-
var value = yesterday(diffObj1);
|
|
519
|
-
text = formatDate(toDateObj, yesterday);
|
|
520
|
-
} else if (dateObj.getMonth() > curDateObj.getMonth() || dateObj.getDate() > curDateObj.getDate()) {
|
|
521
|
-
var value = tomorrow(diffObj1);
|
|
522
|
-
text = formatDate(toDateObj, value);
|
|
523
|
-
}
|
|
524
|
-
} else {
|
|
525
|
-
var value = others(diffObj1);
|
|
526
|
-
text = formatDate(toDateObj, value);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
let i18nText = isSuffixEnable && suffix !== '' ? `${key}.${suffix}` : key;
|
|
531
|
-
let titleFormated = titleString === undefined ? formatDate(to, titleFormat) : titleString;
|
|
532
|
-
return {
|
|
533
|
-
formatedDate: text,
|
|
534
|
-
values: values,
|
|
535
|
-
i18nText,
|
|
536
|
-
title: titleFormated
|
|
537
|
-
};
|
|
538
486
|
}
|
|
@@ -17,21 +17,21 @@ var _datetimejs = _interopRequireDefault(require("@zohodesk/datetimejs"));
|
|
|
17
17
|
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
19
|
|
|
20
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
20
|
+
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); }
|
|
21
21
|
|
|
22
22
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
23
23
|
|
|
24
24
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
25
25
|
|
|
26
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
26
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
27
27
|
|
|
28
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
28
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
29
29
|
|
|
30
30
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
31
31
|
|
|
32
32
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
33
33
|
|
|
34
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
34
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
35
35
|
|
|
36
36
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
37
37
|
|
|
@@ -92,9 +92,8 @@ var DateTimeDiffFormat = /*#__PURE__*/function (_React$Component) {
|
|
|
92
92
|
title = _this$props$title === void 0 ? null : _this$props$title,
|
|
93
93
|
isOverdue = _this$props.isOverdue,
|
|
94
94
|
timeFormat = _this$props.timeFormat,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
defaultDateTimeFormat = _this$props.defaultDateTimeFormat;
|
|
95
|
+
datePattern = _this$props.datePattern,
|
|
96
|
+
isEnabledCurrentYear = _this$props.isEnabledCurrentYear;
|
|
98
97
|
|
|
99
98
|
var fromDateObj = _datetimejs["default"].toDate(_datetimejs["default"].tz.utcToTz(from, fromTzData)).getTime();
|
|
100
99
|
|
|
@@ -128,7 +127,6 @@ var DateTimeDiffFormat = /*#__PURE__*/function (_React$Component) {
|
|
|
128
127
|
seconds: diff.s,
|
|
129
128
|
years: diff.y,
|
|
130
129
|
yDays: diff.yd,
|
|
131
|
-
yMonth: diff.m,
|
|
132
130
|
isWithInAWeek: withInAWeak,
|
|
133
131
|
suffix: suffix,
|
|
134
132
|
crntDate: new Date(from).getDate(),
|
|
@@ -146,9 +144,20 @@ var DateTimeDiffFormat = /*#__PURE__*/function (_React$Component) {
|
|
|
146
144
|
betweenleepYears: (0, _utils.getLyears)(from, to),
|
|
147
145
|
isOverdue: isOverdue,
|
|
148
146
|
timeFormat: timeFormat,
|
|
149
|
-
datePattern:
|
|
150
|
-
|
|
151
|
-
};
|
|
147
|
+
datePattern: datePattern,
|
|
148
|
+
dateTimePattern: "".concat(datePattern, " ").concat(timeFormat)
|
|
149
|
+
}; //In if condition we'll remove year and set date format if the current year is not required
|
|
150
|
+
//In else part we'll set the date format as it is
|
|
151
|
+
|
|
152
|
+
if (isEnabledCurrentYear === true && diffObj1.years === 0 && diffObj1.tYear === diffObj1.crntYear) {
|
|
153
|
+
var dateFormat = (0, _utils.getDatePatternWithoutYear)(datePattern);
|
|
154
|
+
diffObj1.dateFormat = dateFormat;
|
|
155
|
+
diffObj1.dateTimeFormat = "".concat(dateFormat, " ").concat(timeFormat);
|
|
156
|
+
} else {
|
|
157
|
+
diffObj1.dateFormat = datePattern;
|
|
158
|
+
diffObj1.dateTimeFormat = "".concat(datePattern, " ").concat(timeFormat);
|
|
159
|
+
}
|
|
160
|
+
|
|
152
161
|
var key = '';
|
|
153
162
|
var values = [];
|
|
154
163
|
var text = null;
|
|
@@ -190,17 +199,42 @@ var DateTimeDiffFormat = /*#__PURE__*/function (_React$Component) {
|
|
|
190
199
|
text = (0, _utils.formatDate)(toDateObj, _value, diffObj1);
|
|
191
200
|
}
|
|
192
201
|
} else {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
202
|
+
var dateObj = new Date(toDateObj);
|
|
203
|
+
var curDateObj = new Date(fromDateObj);
|
|
204
|
+
var diffDayType = diffObj1.yDays; //In this condition, to calculate different days we have copied it from live --> diffDayType
|
|
205
|
+
|
|
206
|
+
if (isOverdue && dateObj.getDate() < curDateObj.getDate() && diffObj1.yDays == 0) {
|
|
207
|
+
diffDayType = -1;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (!isOverdue) {
|
|
211
|
+
var diffHr = dateObj.getHours() - curDateObj.getHours();
|
|
212
|
+
|
|
213
|
+
if (diffHr < 0) {
|
|
214
|
+
diffDayType += 1;
|
|
215
|
+
} else if (diffHr == 0) {
|
|
216
|
+
var diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
|
|
217
|
+
|
|
218
|
+
if (diffMins < 0) {
|
|
219
|
+
diffDayType += 1;
|
|
220
|
+
} else if (diffMins == 0) {
|
|
221
|
+
var diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
|
|
222
|
+
|
|
223
|
+
if (diffSec < 0) {
|
|
224
|
+
diffDayType += 1;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
196
229
|
|
|
230
|
+
if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
|
|
197
231
|
if (dateObj.getDate() === curDateObj.getDate()) {
|
|
198
232
|
var value = today && today(diffObj1) || others(diffObj1);
|
|
199
233
|
text = (0, _utils.formatDate)(toDateObj, value);
|
|
200
234
|
} else if (dateObj.getMonth() === curDateObj.getMonth() && dateObj.getDate() < curDateObj.getDate() || dateObj.getMonth() < curDateObj.getMonth()) {
|
|
201
235
|
var value = yesterday && yesterday(diffObj1) || others(diffObj1);
|
|
202
236
|
text = (0, _utils.formatDate)(toDateObj, value);
|
|
203
|
-
} else if (
|
|
237
|
+
} else if (!isOverdue && diff.y === 0 && diffDayType === 1) {
|
|
204
238
|
var value = tomorrow && tomorrow(diffObj1) || others(diffObj1);
|
|
205
239
|
text = (0, _utils.formatDate)(toDateObj, value);
|
|
206
240
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
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
|
|
@@ -19,15 +19,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
19
19
|
|
|
20
20
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
21
21
|
|
|
22
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
22
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
23
23
|
|
|
24
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
24
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
25
25
|
|
|
26
26
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
27
27
|
|
|
28
28
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
29
29
|
|
|
30
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
30
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
31
31
|
|
|
32
32
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
33
33
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
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
|
|
@@ -27,15 +27,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
27
27
|
|
|
28
28
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
29
29
|
|
|
30
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
30
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
31
31
|
|
|
32
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
32
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
33
33
|
|
|
34
34
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
35
35
|
|
|
36
36
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
37
37
|
|
|
38
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
38
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
39
39
|
|
|
40
40
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
41
41
|
|
package/lib/components/I18N.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
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
|
|
@@ -27,15 +27,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
27
27
|
|
|
28
28
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
29
29
|
|
|
30
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
30
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
31
31
|
|
|
32
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
32
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
33
33
|
|
|
34
34
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
35
35
|
|
|
36
36
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
37
37
|
|
|
38
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
38
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
39
39
|
|
|
40
40
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
41
41
|
|