@zohodesk/i18n 1.0.0-beta.2 → 1.0.0-beta.20
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 +80 -5
- package/es/I18NContext.js +1 -2
- package/es/components/DateTimeDiffFormat.js +191 -184
- package/es/components/FormatText.js +4 -25
- package/es/components/HOCI18N.js +33 -45
- package/es/components/I18N.js +46 -63
- package/es/components/I18NProvider.js +54 -84
- package/es/components/PluralFormat.js +29 -48
- package/es/components/UserTimeDiffFormat.js +65 -70
- package/es/components/__tests__/DateTimeDiffFormat.spec.js +868 -657
- package/es/components/__tests__/FormatText.spec.js +20 -17
- package/es/components/__tests__/HOCI18N.spec.js +18 -22
- package/es/components/__tests__/I18N.spec.js +20 -19
- package/es/components/__tests__/I18NProvider.spec.js +36 -45
- package/es/components/__tests__/PluralFormat.spec.js +20 -17
- package/es/components/__tests__/UserTimeDiffFormat.spec.js +1343 -1095
- 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 -6
- package/es/utils.js +250 -385
- package/lib/I18NContext.js +6 -6
- package/lib/components/DateTimeDiffFormat.js +166 -123
- package/lib/components/FormatText.js +32 -22
- package/lib/components/HOCI18N.js +47 -23
- package/lib/components/I18N.js +60 -36
- package/lib/components/I18NProvider.js +76 -69
- package/lib/components/PluralFormat.js +42 -32
- package/lib/components/UserTimeDiffFormat.js +81 -54
- package/lib/components/__tests__/DateTimeDiffFormat.spec.js +815 -629
- package/lib/components/__tests__/FormatText.spec.js +23 -25
- package/lib/components/__tests__/HOCI18N.spec.js +26 -34
- package/lib/components/__tests__/I18N.spec.js +21 -26
- package/lib/components/__tests__/I18NProvider.spec.js +43 -51
- package/lib/components/__tests__/PluralFormat.spec.js +24 -28
- package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1256 -1039
- 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 +73 -119
- package/lib/utils.js +222 -329
- package/package.json +29 -29
- package/src/I18NContext.js +3 -0
- package/src/components/DateTimeDiffFormat.js +256 -0
- package/src/components/FormatText.js +14 -0
- package/src/components/HOCI18N.js +37 -0
- package/src/components/I18N.js +72 -0
- package/src/components/I18NProvider.js +110 -0
- package/src/components/PluralFormat.js +37 -0
- package/src/components/UserTimeDiffFormat.js +97 -0
- package/src/components/__tests__/DateTimeDiffFormat.spec.js +618 -0
- package/src/components/__tests__/FormatText.spec.js +27 -0
- package/src/components/__tests__/HOCI18N.spec.js +33 -0
- package/src/components/__tests__/I18N.spec.js +30 -0
- package/src/components/__tests__/I18NProvider.spec.js +65 -0
- package/src/components/__tests__/PluralFormat.spec.js +28 -0
- package/src/components/__tests__/UserTimeDiffFormat.spec.js +1076 -0
- package/src/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -0
- package/src/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -0
- package/src/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -0
- package/src/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -0
- package/src/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -0
- package/src/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -0
- package/src/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -0
- package/src/index.js +33 -0
- package/src/utils.js +527 -0
- package/.DS_Store +0 -0
- package/es/components/NewDateFormat.js +0 -50
- package/es/offset.js +0 -629
- package/es/timezones.js +0 -112
- package/lib/components/NewDateFormat.js +0 -68
- package/lib/offset.js +0 -634
- package/lib/timezones.js +0 -120
package/lib/utils.js
CHANGED
|
@@ -1,44 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.browserOffset = undefined;
|
|
7
|
-
|
|
8
|
-
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
|
9
|
-
|
|
10
6
|
exports.formatDate = formatDate;
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
13
|
-
exports.unescapeUnicode = unescapeUnicode;
|
|
14
|
-
exports.getValues = getValues;
|
|
15
|
-
exports.getI18NValue = getI18NValue;
|
|
7
|
+
exports.getDatePatternWithoutYear = getDatePatternWithoutYear;
|
|
8
|
+
exports.getDiffObj = getDiffObj;
|
|
16
9
|
exports.getI18NInfo = getI18NInfo;
|
|
10
|
+
exports.getI18NValue = getI18NValue;
|
|
11
|
+
exports.getLocalizedValue = getLocalizedValue;
|
|
12
|
+
exports.getLyears = getLyears;
|
|
13
|
+
exports.getSuffix = getSuffix;
|
|
14
|
+
exports.getValues = getValues;
|
|
17
15
|
exports.isToday = isToday;
|
|
18
|
-
exports.isYesterday = isYesterday;
|
|
19
16
|
exports.isTomorrow = isTomorrow;
|
|
20
|
-
exports.isWithinAWeek = isWithinAWeek;
|
|
21
17
|
exports.isTwoWeeksOrMore = isTwoWeeksOrMore;
|
|
22
|
-
exports.
|
|
23
|
-
exports.
|
|
24
|
-
exports.
|
|
25
|
-
exports.
|
|
18
|
+
exports.isWithinAWeek = isWithinAWeek;
|
|
19
|
+
exports.isYesterday = isYesterday;
|
|
20
|
+
exports.pad = pad;
|
|
21
|
+
exports.replaceI18NValuesWithRegex = replaceI18NValuesWithRegex;
|
|
22
|
+
exports.setLocalizedData = setLocalizedData;
|
|
23
|
+
exports.unescapeUnicode = unescapeUnicode;
|
|
26
24
|
exports.userDateFormat = userDateFormat;
|
|
27
|
-
exports.getDiffObj = getDiffObj;
|
|
28
|
-
exports.getLyears = getLyears;
|
|
29
|
-
exports.getSuffix = getSuffix;
|
|
30
|
-
exports.getFormatedDate = getFormatedDate;
|
|
31
25
|
|
|
32
|
-
var
|
|
26
|
+
var _datetimejs = _interopRequireDefault(require("@zohodesk/datetimejs"));
|
|
33
27
|
|
|
34
|
-
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
29
|
+
|
|
30
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
35
31
|
|
|
36
|
-
var browserOffset = exports.browserOffset = -new Date().getTimezoneOffset();
|
|
37
32
|
var dateFormat = {
|
|
38
33
|
dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
|
39
34
|
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'],
|
|
40
35
|
timeNames: ['a', 'p', 'am', 'pm', 'A', 'P', 'AM', 'PM']
|
|
41
36
|
};
|
|
37
|
+
|
|
42
38
|
function formatDate(dateMill, mask, dateDiffObj) {
|
|
43
39
|
if (mask === 'facebookFormat') {
|
|
44
40
|
var hours = dateDiffObj.hours,
|
|
@@ -50,28 +46,34 @@ function formatDate(dateMill, mask, dateDiffObj) {
|
|
|
50
46
|
crntMonth = dateDiffObj.crntMonth;
|
|
51
47
|
|
|
52
48
|
if (years > 0) {
|
|
53
|
-
return years
|
|
49
|
+
return "".concat(years, "y");
|
|
54
50
|
} else if (yDays > 0) {
|
|
55
51
|
var isFeb = crntMonth === 1;
|
|
56
52
|
var isThoneMonth = [0, 2, 4, 6, 7, 9, 11].indexOf(crntMonth) != -1;
|
|
53
|
+
|
|
57
54
|
var weekCal = function weekCal(calDays) {
|
|
58
55
|
var weeks = calDays / 7;
|
|
59
|
-
return weeks < 1 ? calDays
|
|
56
|
+
return weeks < 1 ? "".concat(calDays, "d") : "".concat(Math.trunc(weeks), "w");
|
|
60
57
|
};
|
|
58
|
+
|
|
61
59
|
if (!isFeb) {
|
|
62
60
|
return isThoneMonth === true ? yDays === 31 ? '1m' : weekCal(yDays) : yDays === 30 ? '1m' : weekCal(yDays);
|
|
63
61
|
}
|
|
62
|
+
|
|
64
63
|
if (betweenleepYears != 0) {
|
|
65
64
|
return isFeb === true && yDays === 28 ? '1m' : weekCal(yDays);
|
|
66
65
|
}
|
|
66
|
+
|
|
67
67
|
return isFeb === true && yDays === 29 ? '1m' : weekCal(yDays);
|
|
68
68
|
} else if (hours < 24 && hours > 0) {
|
|
69
|
-
return hours
|
|
69
|
+
return "".concat(hours, "h");
|
|
70
70
|
} else if (minutes < 60 && hours > 1) {
|
|
71
|
-
return minutes
|
|
71
|
+
return "".concat(minutes, "m");
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
|
|
74
|
+
return seconds === 0 ? 'now' : "".concat(seconds, "s");
|
|
74
75
|
}
|
|
76
|
+
|
|
75
77
|
var date = new Date(dateMill);
|
|
76
78
|
var d = date.getDate();
|
|
77
79
|
var D = date.getDay();
|
|
@@ -112,34 +114,36 @@ function formatDate(dateMill, mask, dateDiffObj) {
|
|
|
112
114
|
A: H < 12 ? dateFormat.timeNames[6] : dateFormat.timeNames[7],
|
|
113
115
|
T: H < 12 ? dateFormat.timeNames[4] : dateFormat.timeNames[5]
|
|
114
116
|
};
|
|
115
|
-
|
|
116
117
|
var token = /D{1,4}|M{1,4}|YY(?:YY)?|([HhmsA])\1?|[LloSZWN]|\[[^\]]*\]|'[^']*'/gi;
|
|
117
118
|
var dat = mask.replace(token, function (match) {
|
|
118
119
|
if (match in flags) {
|
|
119
120
|
return flags[match];
|
|
120
121
|
}
|
|
122
|
+
|
|
121
123
|
return match.slice(1, match.length - 1);
|
|
122
124
|
});
|
|
123
125
|
return dat;
|
|
124
126
|
}
|
|
127
|
+
|
|
125
128
|
function pad(n) {
|
|
126
129
|
var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
127
|
-
var z = arguments[2];
|
|
128
|
-
|
|
130
|
+
var z = arguments.length > 2 ? arguments[2] : undefined;
|
|
129
131
|
z = z || '0';
|
|
130
|
-
n =
|
|
132
|
+
n = "".concat(n);
|
|
131
133
|
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
|
|
132
134
|
}
|
|
135
|
+
|
|
133
136
|
function replaceI18NValuesWithRegex(i18nStr, values) {
|
|
134
137
|
if (typeof values !== 'undefined') {
|
|
135
138
|
if (Array.isArray(values)) {
|
|
136
139
|
for (var i = 0; i < values.length; i++) {
|
|
137
|
-
i18nStr = i18nStr.replace(new RegExp(
|
|
140
|
+
i18nStr = i18nStr.replace(new RegExp("\\{".concat(i, "\\}"), 'g'), values[i]);
|
|
138
141
|
}
|
|
139
142
|
} else {
|
|
140
143
|
i18nStr = i18nStr.replace(new RegExp('\\{0\\}', 'g'), values);
|
|
141
144
|
}
|
|
142
145
|
}
|
|
146
|
+
|
|
143
147
|
return i18nStr;
|
|
144
148
|
}
|
|
145
149
|
|
|
@@ -148,124 +152,162 @@ function unescapeUnicode(str) {
|
|
|
148
152
|
return String.fromCharCode(parseInt(m1, 16));
|
|
149
153
|
});
|
|
150
154
|
}
|
|
155
|
+
|
|
151
156
|
function getValues() {
|
|
152
157
|
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
153
|
-
var diff = arguments[1];
|
|
154
|
-
|
|
158
|
+
var diff = arguments.length > 1 ? arguments[1] : undefined;
|
|
155
159
|
return params.map(function (param) {
|
|
156
160
|
return diff[param];
|
|
157
161
|
});
|
|
158
162
|
}
|
|
163
|
+
|
|
164
|
+
var localizedData = {};
|
|
165
|
+
|
|
166
|
+
function setLocalizedData(data) {
|
|
167
|
+
localizedData = data;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function getLocalizedValue() {
|
|
171
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
172
|
+
type = _ref.type,
|
|
173
|
+
moduleName = _ref.moduleName,
|
|
174
|
+
apiName = _ref.apiName,
|
|
175
|
+
fieldValue = _ref.fieldValue;
|
|
176
|
+
|
|
177
|
+
var localizedValue = localizedData;
|
|
178
|
+
|
|
179
|
+
switch (type) {
|
|
180
|
+
case 'field':
|
|
181
|
+
['Field', moduleName, apiName].map(function (key) {
|
|
182
|
+
localizedValue = localizedValue[key] || '';
|
|
183
|
+
});
|
|
184
|
+
break;
|
|
185
|
+
|
|
186
|
+
case 'picklist':
|
|
187
|
+
['PickListValue', moduleName, apiName, fieldValue].map(function (key) {
|
|
188
|
+
localizedValue = localizedValue[key] || '';
|
|
189
|
+
});
|
|
190
|
+
break;
|
|
191
|
+
|
|
192
|
+
default:
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return localizedValue || null;
|
|
197
|
+
}
|
|
198
|
+
|
|
159
199
|
function getI18NValue(i18n) {
|
|
160
200
|
if (typeof i18n === 'undefined') {
|
|
161
201
|
return function (key) {
|
|
162
202
|
return key;
|
|
163
203
|
};
|
|
164
204
|
}
|
|
165
|
-
|
|
205
|
+
|
|
206
|
+
return function (key, values, localizedProps) {
|
|
207
|
+
var localizedValue = localizedProps ? getLocalizedValue(localizedProps) : null;
|
|
166
208
|
var i18nStr = i18n[key];
|
|
209
|
+
|
|
167
210
|
if (i18nStr === undefined) {
|
|
168
|
-
return key;
|
|
211
|
+
return localizedValue || key;
|
|
169
212
|
}
|
|
213
|
+
|
|
170
214
|
i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
|
|
171
|
-
return unescapeUnicode(i18nStr);
|
|
215
|
+
return localizedValue || unescapeUnicode(i18nStr);
|
|
172
216
|
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// function getValues(params = [], diff) {
|
|
217
|
+
} // function getValues(params = [], diff) {
|
|
176
218
|
// return params.map(param => {
|
|
177
219
|
// return diff[param];
|
|
178
220
|
// });
|
|
179
221
|
// }
|
|
222
|
+
|
|
223
|
+
|
|
180
224
|
function getI18NInfo(toDateObj, props, diffObj) {
|
|
181
225
|
var key = null,
|
|
182
|
-
values
|
|
226
|
+
values,
|
|
183
227
|
text = null;
|
|
228
|
+
|
|
184
229
|
if (typeof props === 'function') {
|
|
185
230
|
var value = props(diffObj1);
|
|
186
231
|
key = value.key;
|
|
187
232
|
values = getValues(value.params, diffObj);
|
|
188
|
-
} else if (
|
|
233
|
+
} else if (_typeof(props) === 'object') {
|
|
189
234
|
key = props.key;
|
|
190
235
|
values = getValues(props.params, diffObj);
|
|
191
236
|
} else if (typeof props === 'string') {
|
|
192
237
|
text = toDateObj.format(props);
|
|
193
238
|
}
|
|
194
|
-
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
key: key,
|
|
242
|
+
values: values,
|
|
243
|
+
text: text
|
|
244
|
+
};
|
|
195
245
|
}
|
|
246
|
+
|
|
196
247
|
function isToday(fromDate, toDate) {
|
|
197
248
|
var TODAY = toDate.clone().startOf('day');
|
|
198
249
|
return fromDate.isSame(TODAY, 'd');
|
|
199
250
|
}
|
|
251
|
+
|
|
200
252
|
function isYesterday(fromDate, toDate) {
|
|
201
253
|
var YESTERDAY = toDate.clone().subtract(1, 'days').startOf('day');
|
|
202
254
|
return fromDate.isSame(YESTERDAY, 'd');
|
|
203
255
|
}
|
|
256
|
+
|
|
204
257
|
function isTomorrow(fromDate, toDate) {
|
|
205
258
|
return isYesterday(toDate, fromDate);
|
|
206
259
|
}
|
|
260
|
+
|
|
207
261
|
function isWithinAWeek(fromDate, toDate) {
|
|
208
262
|
var A_WEEK_OLD = toDate.clone().subtract(7, 'days').startOf('day');
|
|
209
263
|
return fromDate.isAfter(A_WEEK_OLD);
|
|
210
264
|
}
|
|
265
|
+
|
|
211
266
|
function isTwoWeeksOrMore(fromDate, toDate) {
|
|
212
267
|
return !isWithinAWeek(fromDate, toDate);
|
|
213
268
|
}
|
|
214
269
|
|
|
215
|
-
function
|
|
216
|
-
var
|
|
217
|
-
|
|
218
|
-
return timeinlong;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function getUtcTimeStamp(date) {
|
|
222
|
-
var timestamp = date ? new Date(date).getTime() : new Date().getTime();
|
|
223
|
-
var browserOffset = -new Date().getTimezoneOffset();
|
|
224
|
-
return convertTimezone(timestamp, browserOffset, 0);
|
|
225
|
-
}
|
|
270
|
+
function getDatePatternWithoutYear(datePattern) {
|
|
271
|
+
var dateObj;
|
|
272
|
+
var delemiter;
|
|
226
273
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
274
|
+
if (datePattern.indexOf('.') !== -1) {
|
|
275
|
+
dateObj = datePattern.split('.');
|
|
276
|
+
delemiter = '.';
|
|
277
|
+
} else if (datePattern.indexOf('-') !== -1) {
|
|
278
|
+
dateObj = datePattern.split('-');
|
|
279
|
+
delemiter = '-';
|
|
280
|
+
} else if (datePattern.indexOf('/') !== -1) {
|
|
281
|
+
dateObj = datePattern.split('/');
|
|
282
|
+
delemiter = '/';
|
|
283
|
+
} else {
|
|
284
|
+
dateObj = datePattern.split(' ');
|
|
285
|
+
delemiter = ' ';
|
|
235
286
|
}
|
|
236
|
-
return browserOffset;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function convertUtcToUserTz(date, tzData) {
|
|
240
|
-
var utcTimeStamp = getUtcTimeStamp(date);
|
|
241
|
-
var offset = getOffset(utcTimeStamp, tzData);
|
|
242
|
-
var convertedTimeStamp = convertTimezone(utcTimeStamp, 0, offset);
|
|
243
|
-
return new Date(convertedTimeStamp);
|
|
244
|
-
}
|
|
245
287
|
|
|
246
|
-
function
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
var offset = getOffset(timestamp, tzData);
|
|
250
|
-
var utcTimeStamp = convertTimezone(timestamp, offset, 0);
|
|
251
|
-
var convertedTimeStamp = convertTimezone(utcTimeStamp, 0, browserOffset);
|
|
252
|
-
return new Date(convertedTimeStamp);
|
|
288
|
+
return dateObj.filter(function (data) {
|
|
289
|
+
return ['yy', 'yyyy'].indexOf(data) === -1;
|
|
290
|
+
}).join(delemiter);
|
|
253
291
|
}
|
|
254
292
|
|
|
255
|
-
function userDateFormat(getI18NValue,
|
|
256
|
-
return function (to,
|
|
257
|
-
var today =
|
|
258
|
-
yesterday =
|
|
259
|
-
tomorrow =
|
|
260
|
-
others =
|
|
293
|
+
function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isEnabledCurrentYear) {
|
|
294
|
+
return function (to, _ref2, ago, later) {
|
|
295
|
+
var today = _ref2.today,
|
|
296
|
+
yesterday = _ref2.yesterday,
|
|
297
|
+
tomorrow = _ref2.tomorrow,
|
|
298
|
+
others = _ref2.others;
|
|
261
299
|
var isSuffixEnable = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
262
|
-
var format = arguments[5];
|
|
300
|
+
var format = arguments.length > 5 ? arguments[5] : undefined;
|
|
301
|
+
|
|
302
|
+
var fromDateObj = _datetimejs["default"].toDate(_datetimejs["default"].tz.utcToTz(null, timezoneData));
|
|
263
303
|
|
|
264
|
-
var
|
|
265
|
-
var toDateObj = convertUtcToUserTz(to, tzData);
|
|
304
|
+
var toDateObj = _datetimejs["default"].toDate(_datetimejs["default"].tz.utcToTz(to, timezoneData));
|
|
266
305
|
|
|
267
306
|
var diffMin = new Date(to).getTime() - new Date().getTime();
|
|
268
|
-
var
|
|
307
|
+
var from = new Date();
|
|
308
|
+
from = from.toISOString();
|
|
309
|
+
var suffix;
|
|
310
|
+
|
|
269
311
|
if (diffMin < 0) {
|
|
270
312
|
suffix = ago || '';
|
|
271
313
|
} else if (diffMin > 0) {
|
|
@@ -273,6 +315,7 @@ function userDateFormat(getI18NValue, tzData) {
|
|
|
273
315
|
} else {
|
|
274
316
|
suffix = '';
|
|
275
317
|
}
|
|
318
|
+
|
|
276
319
|
var diff = getDiffObj(diffMin);
|
|
277
320
|
var withInAWeak = diff.y === 0 && diff.yd <= 7;
|
|
278
321
|
var diffObj = {
|
|
@@ -295,44 +338,57 @@ function userDateFormat(getI18NValue, tzData) {
|
|
|
295
338
|
seconds: diff.s,
|
|
296
339
|
years: diff.y,
|
|
297
340
|
yDays: diff.yd,
|
|
341
|
+
crntYear: new Date(from).getFullYear(),
|
|
342
|
+
tYear: new Date(to).getFullYear(),
|
|
298
343
|
isWithInAWeek: withInAWeak,
|
|
299
|
-
suffix: suffix
|
|
300
|
-
|
|
301
|
-
|
|
344
|
+
suffix: suffix,
|
|
345
|
+
timeFormat: timeFormat,
|
|
346
|
+
datePattern: datePattern,
|
|
347
|
+
dateTimePattern: "".concat(datePattern, " ").concat(timeFormat)
|
|
348
|
+
}; //In if condition we'll remove year and set date format if the current year is not required
|
|
349
|
+
//In else part we'll set the date format as it is
|
|
350
|
+
|
|
351
|
+
if (isEnabledCurrentYear === true && diffObj1.years === 0 && diffObj1.tYear === diffObj1.crntYear) {
|
|
352
|
+
var _dateFormat = getDatePatternWithoutYear(datePattern);
|
|
353
|
+
|
|
354
|
+
diffObj1.dateFormat = _dateFormat;
|
|
355
|
+
diffObj1.dateTimeFormat = "".concat(_dateFormat, " ").concat(timeFormat);
|
|
356
|
+
} else {
|
|
357
|
+
diffObj1.dateFormat = datePattern;
|
|
358
|
+
diffObj1.dateTimeFormat = "".concat(datePattern, " ").concat(timeFormat);
|
|
359
|
+
} //var daysDiff = toDateObj.diff(fromDateObj, 'days');
|
|
360
|
+
|
|
302
361
|
|
|
303
362
|
var key = '';
|
|
304
363
|
var values = [];
|
|
305
364
|
var text = null;
|
|
365
|
+
|
|
306
366
|
if (format) {
|
|
307
|
-
var years
|
|
308
|
-
|
|
309
|
-
days = void 0,
|
|
310
|
-
hours = void 0,
|
|
311
|
-
minutes = void 0,
|
|
312
|
-
seconds = void 0;
|
|
313
|
-
|
|
314
|
-
years = diffObj1.years > 1 ? '2' : diffObj1.years;
|
|
315
|
-
// months = diffObj1.months > 1 ? '2' : diffObj1.months;
|
|
367
|
+
var years, months, days, hours, minutes, seconds;
|
|
368
|
+
years = diffObj1.years > 1 ? '2' : diffObj1.years; // months = diffObj1.months > 1 ? '2' : diffObj1.months;
|
|
316
369
|
// days = diffObj1.days > 1 ? '2' : diffObj1.days;
|
|
370
|
+
|
|
317
371
|
days = diff.yd > 1 ? '2' : diff.yd;
|
|
318
372
|
hours = diffObj1.hours > 1 ? '2' : diffObj1.hours;
|
|
319
|
-
minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes;
|
|
320
|
-
//seconds = diffObj1.seconds > 1 ? '2' : diffObj1.seconds;
|
|
373
|
+
minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes; //seconds = diffObj1.seconds > 1 ? '2' : diffObj1.seconds;
|
|
321
374
|
// let pattern = '' + years + months + days + hours + minutes + seconds;
|
|
375
|
+
|
|
322
376
|
var count = 0;
|
|
323
377
|
var pattern = [years, days, hours, minutes].reduce(function (res, next) {
|
|
324
378
|
if (count === 2 || next === 0) {
|
|
325
|
-
res = res
|
|
379
|
+
res = "".concat(res, "0");
|
|
326
380
|
} else if (next !== 0) {
|
|
327
381
|
count++;
|
|
328
382
|
res = res + next;
|
|
329
383
|
} else {
|
|
330
384
|
res = res + next;
|
|
331
385
|
}
|
|
386
|
+
|
|
332
387
|
return res;
|
|
333
388
|
}, '');
|
|
334
389
|
var value = format(diffObj1, pattern);
|
|
335
|
-
|
|
390
|
+
|
|
391
|
+
if (value && _typeof(value) === 'object') {
|
|
336
392
|
key = value.key;
|
|
337
393
|
values = getValues(value.params, diffObj);
|
|
338
394
|
isSuffixEnable = true;
|
|
@@ -340,44 +396,82 @@ function userDateFormat(getI18NValue, tzData) {
|
|
|
340
396
|
text = formatDate(toDateObj, value);
|
|
341
397
|
}
|
|
342
398
|
} else {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
399
|
+
var dateObj = new Date(toDateObj);
|
|
400
|
+
var curDateObj = new Date(fromDateObj);
|
|
401
|
+
var diffDayType = diffObj1.yDays; //In this condition, to calculate different days we have copied it from live --> diffDayType
|
|
402
|
+
|
|
403
|
+
if (isOverdue && dateObj.getDate() < curDateObj.getDate() && diffObj1.yDays == 0) {
|
|
404
|
+
diffDayType = -1;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (!isOverdue) {
|
|
408
|
+
var diffHr = dateObj.getHours() - curDateObj.getHours();
|
|
409
|
+
|
|
410
|
+
if (diffHr < 0) {
|
|
411
|
+
diffDayType += 1;
|
|
412
|
+
} else if (diffHr == 0) {
|
|
413
|
+
var diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
|
|
414
|
+
|
|
415
|
+
if (diffMins < 0) {
|
|
416
|
+
diffDayType += 1;
|
|
417
|
+
} else if (diffMins == 0) {
|
|
418
|
+
var diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
|
|
419
|
+
|
|
420
|
+
if (diffSec < 0) {
|
|
421
|
+
diffDayType += 1;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
|
|
428
|
+
if (today && dateObj.getDate() === curDateObj.getDate()) {
|
|
429
|
+
if (_typeof(today) === 'object') {
|
|
348
430
|
key = today.key;
|
|
349
431
|
values = getValues(today.params, diffObj);
|
|
350
432
|
isSuffixEnable = true;
|
|
351
433
|
} else if (typeof today === 'string') {
|
|
352
434
|
text = formatDate(toDateObj, today);
|
|
353
435
|
}
|
|
354
|
-
} else if (dateObj.getDate() < curDateObj.getDate()) {
|
|
355
|
-
if (
|
|
436
|
+
} else if (yesterday && dateObj.getMonth() === curDateObj.getMonth() && dateObj.getDate() < curDateObj.getDate() || yesterday && dateObj.getMonth() < curDateObj.getMonth()) {
|
|
437
|
+
if (_typeof(yesterday) === 'object') {
|
|
356
438
|
key = yesterday.key;
|
|
357
439
|
values = getValues(yesterday.params, diffObj);
|
|
358
440
|
} else if (typeof yesterday === 'string') {
|
|
359
441
|
text = formatDate(toDateObj, yesterday);
|
|
360
442
|
}
|
|
361
|
-
} else if (
|
|
362
|
-
if (
|
|
443
|
+
} else if (tomorrow && !isOverdue && diff.y === 0 && diffDayType === 1) {
|
|
444
|
+
if (_typeof(tomorrow) === 'object') {
|
|
363
445
|
key = tomorrow.key;
|
|
364
446
|
values = getValues(tomorrow.params, diffObj);
|
|
365
447
|
} else if (typeof tomorrow === 'string') {
|
|
366
448
|
text = formatDate(toDateObj, tomorrow);
|
|
367
449
|
}
|
|
450
|
+
} else {
|
|
451
|
+
var _value = others(diffObj1);
|
|
452
|
+
|
|
453
|
+
if (_typeof(_value) === 'object') {
|
|
454
|
+
key = _value.key;
|
|
455
|
+
values = getValues(_value.params, diffObj);
|
|
456
|
+
isSuffixEnable = true;
|
|
457
|
+
} else if (typeof _value === 'string') {
|
|
458
|
+
text = formatDate(toDateObj, _value);
|
|
459
|
+
}
|
|
368
460
|
}
|
|
369
461
|
} else {
|
|
370
|
-
var
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
462
|
+
var _value2 = others(diffObj1);
|
|
463
|
+
|
|
464
|
+
if (_typeof(_value2) === 'object') {
|
|
465
|
+
key = _value2.key;
|
|
466
|
+
values = getValues(_value2.params, diffObj);
|
|
374
467
|
isSuffixEnable = true;
|
|
375
|
-
} else if (typeof
|
|
376
|
-
text = formatDate(toDateObj,
|
|
468
|
+
} else if (typeof _value2 === 'string') {
|
|
469
|
+
text = formatDate(toDateObj, _value2);
|
|
377
470
|
}
|
|
378
471
|
}
|
|
379
472
|
}
|
|
380
|
-
|
|
473
|
+
|
|
474
|
+
var key1 = isSuffixEnable && suffix != '' ? "".concat(key, ".").concat(suffix) : key;
|
|
381
475
|
return text || getI18NValue(key1, values);
|
|
382
476
|
};
|
|
383
477
|
}
|
|
@@ -386,10 +480,12 @@ var oneYearInMillis = 31536000000;
|
|
|
386
480
|
var oneDayInMillis = 86400000;
|
|
387
481
|
var oneHourInMillis = 3600000;
|
|
388
482
|
var oneMinuteInMillis = 60000;
|
|
483
|
+
|
|
389
484
|
function convertAsNonExponential(number) {
|
|
390
485
|
if (number.toString().toLowerCase().indexOf('e') !== -1) {
|
|
391
486
|
return number.toFixed(20);
|
|
392
487
|
}
|
|
488
|
+
|
|
393
489
|
return number;
|
|
394
490
|
}
|
|
395
491
|
|
|
@@ -423,16 +519,19 @@ function getLyears(from, to) {
|
|
|
423
519
|
var fromYear = dFrom.getFullYear();
|
|
424
520
|
var toYear = dTo.getFullYear();
|
|
425
521
|
var arrayofLeapYears = [];
|
|
522
|
+
|
|
426
523
|
for (var loopYear = fromYear; loopYear <= toYear; loopYear++) {
|
|
427
524
|
if (loopYear % 4 === 0 && loopYear % 100 !== 0 || loopYear % 100 === 0 && loopYear % 400 === 0) {
|
|
428
525
|
arrayofLeapYears.push(loopYear);
|
|
429
526
|
}
|
|
430
527
|
}
|
|
528
|
+
|
|
431
529
|
return arrayofLeapYears.length;
|
|
432
530
|
}
|
|
433
531
|
|
|
434
532
|
function getSuffix(min, ago, later) {
|
|
435
|
-
var suffix
|
|
533
|
+
var suffix;
|
|
534
|
+
|
|
436
535
|
if (min < 0) {
|
|
437
536
|
suffix = ago || '';
|
|
438
537
|
} else if (min > 0) {
|
|
@@ -440,212 +539,6 @@ function getSuffix(min, ago, later) {
|
|
|
440
539
|
} else {
|
|
441
540
|
suffix = '';
|
|
442
541
|
}
|
|
443
|
-
return suffix;
|
|
444
|
-
}
|
|
445
542
|
|
|
446
|
-
|
|
447
|
-
var fromDateObj = convertUtcToUserTz(calculateFrom, tzData);
|
|
448
|
-
var toDateObj = convertUtcToUserTz(to, tzData);
|
|
449
|
-
|
|
450
|
-
var diffMin = new Date(to).getTime() - new Date(calculateFrom).getTime();
|
|
451
|
-
var suffix = getSuffix(diffMin, ago, later);
|
|
452
|
-
var diff = getDiffObj(diffMin);
|
|
453
|
-
var withInAWeak = diff.y === 0 && diff.yd <= 7;
|
|
454
|
-
var diffObj = {
|
|
455
|
-
h: diff.h,
|
|
456
|
-
m: diff.m,
|
|
457
|
-
s: diff.s,
|
|
458
|
-
y: diff.y,
|
|
459
|
-
hh: pad(diff.h, 2),
|
|
460
|
-
mm: pad(diff.m, 2),
|
|
461
|
-
ss: pad(diff.s, 2),
|
|
462
|
-
yy: pad(diff.y, 2),
|
|
463
|
-
days: diff.yd,
|
|
464
|
-
yDays: pad(diff.yd, 2),
|
|
465
|
-
isWithInAWeek: withInAWeak,
|
|
466
|
-
suffix: suffix
|
|
467
|
-
};
|
|
468
|
-
var diffObj1 = {
|
|
469
|
-
hours: diff.h,
|
|
470
|
-
minutes: diff.m,
|
|
471
|
-
seconds: diff.s,
|
|
472
|
-
years: diff.y,
|
|
473
|
-
yDays: diff.yd,
|
|
474
|
-
isWithInAWeek: withInAWeak,
|
|
475
|
-
suffix: suffix,
|
|
476
|
-
crntMonth: new Date(to).getMonth(),
|
|
477
|
-
betweenleepYears: getLyears(calculateFrom, to)
|
|
478
|
-
};
|
|
479
|
-
//var daysDiff = toDateObj.diff(fromDateObj, 'days', true);
|
|
480
|
-
var key = '';
|
|
481
|
-
var values = [];
|
|
482
|
-
var text = null;
|
|
483
|
-
var isSuffixEnable = false;
|
|
484
|
-
if (format) {
|
|
485
|
-
var years = void 0,
|
|
486
|
-
months = void 0,
|
|
487
|
-
days = void 0,
|
|
488
|
-
hours = void 0,
|
|
489
|
-
minutes = void 0,
|
|
490
|
-
seconds = void 0;
|
|
491
|
-
years = diffObj1.years > 1 ? '2' : diffObj1.years;
|
|
492
|
-
// months = diffObj1.months > 1 ? '2' : diffObj1.months;
|
|
493
|
-
//days = diffObj1.days > 1 ? '2' : diffObj1.days;
|
|
494
|
-
days = diff.yd > 1 ? '2' : diff.yd;
|
|
495
|
-
hours = diffObj1.hours > 1 ? '2' : diffObj1.hours;
|
|
496
|
-
minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes;
|
|
497
|
-
//seconds = diffObj1.seconds > 1 ? '2' : diffObj1.seconds;
|
|
498
|
-
// let pattern = '' + years + months + days + hours + minutes + seconds;
|
|
499
|
-
var count = 0;
|
|
500
|
-
var pattern = [years, days, hours, minutes].reduce(function (res, next) {
|
|
501
|
-
if (count === 2) {
|
|
502
|
-
res = res + '0';
|
|
503
|
-
} else if (next !== 0) {
|
|
504
|
-
count++;
|
|
505
|
-
res = res + next;
|
|
506
|
-
} else {
|
|
507
|
-
res = res + next;
|
|
508
|
-
}
|
|
509
|
-
return res;
|
|
510
|
-
}, '');
|
|
511
|
-
//let pattern = '' + years + days + hours + minutes;
|
|
512
|
-
var _value2 = format(diffObj1, pattern);
|
|
513
|
-
if (_value2 && (typeof _value2 === 'undefined' ? 'undefined' : _typeof(_value2)) === 'object') {
|
|
514
|
-
key = _value2.key;
|
|
515
|
-
values = getValues(_value2.params, diffObj);
|
|
516
|
-
if (pattern.indexOf('00000') === 0) {
|
|
517
|
-
//suffix ignore for second hook
|
|
518
|
-
isSuffixEnable = false;
|
|
519
|
-
} else {
|
|
520
|
-
isSuffixEnable = true;
|
|
521
|
-
}
|
|
522
|
-
} else if (typeof _value2 === 'string') {
|
|
523
|
-
if (_value2 === 'socialFormat') {
|
|
524
|
-
var defaultRelativeTime = {
|
|
525
|
-
future: function future(t) {
|
|
526
|
-
return 'in ' + t;
|
|
527
|
-
},
|
|
528
|
-
past: function past(t) {
|
|
529
|
-
return t + ' ago';
|
|
530
|
-
},
|
|
531
|
-
present: function present() {
|
|
532
|
-
return 'just now';
|
|
533
|
-
},
|
|
534
|
-
s: function s() {
|
|
535
|
-
return 'a few seconds ago';
|
|
536
|
-
},
|
|
537
|
-
ss: function ss(t) {
|
|
538
|
-
return t + ' seconds ago';
|
|
539
|
-
},
|
|
540
|
-
m: function m() {
|
|
541
|
-
return 'a minute ago';
|
|
542
|
-
},
|
|
543
|
-
mm: function mm(t) {
|
|
544
|
-
return t + ' minutes ago';
|
|
545
|
-
},
|
|
546
|
-
h: function h() {
|
|
547
|
-
return 'an hour ago';
|
|
548
|
-
},
|
|
549
|
-
hh: function hh(t) {
|
|
550
|
-
return t + ' hours ago';
|
|
551
|
-
},
|
|
552
|
-
d: function d() {
|
|
553
|
-
return 'a day ago';
|
|
554
|
-
},
|
|
555
|
-
dd: function dd(t) {
|
|
556
|
-
return t + ' days ago';
|
|
557
|
-
},
|
|
558
|
-
M: function M() {
|
|
559
|
-
return 'a month ago';
|
|
560
|
-
},
|
|
561
|
-
MM: function MM(t) {
|
|
562
|
-
return t + ' months ago';
|
|
563
|
-
},
|
|
564
|
-
y: function y() {
|
|
565
|
-
return 'a year ago';
|
|
566
|
-
},
|
|
567
|
-
yy: function yy(t) {
|
|
568
|
-
return t + ' years ago';
|
|
569
|
-
}
|
|
570
|
-
};
|
|
571
|
-
if (diff.yd === 0) {
|
|
572
|
-
if (diffObj.h < 1) {
|
|
573
|
-
if (diffObj.m < 1) {
|
|
574
|
-
if (diffObj.s < 1) {
|
|
575
|
-
text = defaultRelativeTime.present();
|
|
576
|
-
} else if (diffObj.s === 1) {
|
|
577
|
-
text = defaultRelativeTime.s();
|
|
578
|
-
} else {
|
|
579
|
-
text = defaultRelativeTime.ss(diffObj.s);
|
|
580
|
-
}
|
|
581
|
-
} else if (diffObj.m === 1) {
|
|
582
|
-
text = defaultRelativeTime.m();
|
|
583
|
-
} else {
|
|
584
|
-
text = defaultRelativeTime.mm(diffObj.mm);
|
|
585
|
-
}
|
|
586
|
-
} else if (diffObj.h === 1) {
|
|
587
|
-
text = defaultRelativeTime.h();
|
|
588
|
-
} else {
|
|
589
|
-
text = defaultRelativeTime.hh(diffObj.h);
|
|
590
|
-
}
|
|
591
|
-
} else {
|
|
592
|
-
text = formatDate(toDateObj, 'DD MMM YYYY', diffObj1);
|
|
593
|
-
}
|
|
594
|
-
} else {
|
|
595
|
-
text = formatDate(toDateObj, _value2, diffObj1);
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
} else {
|
|
599
|
-
if (diff.y === 0 && (diff.yd === 0 || diff.yd === 1)) {
|
|
600
|
-
var dateObj = new Date(toDateObj);
|
|
601
|
-
var curDateObj = new Date(fromDateObj);
|
|
602
|
-
if (dateObj.getDate() === curDateObj.getDate()) {
|
|
603
|
-
if (typeof today === 'function') {
|
|
604
|
-
var value = today(diffObj1);
|
|
605
|
-
key = value.key;
|
|
606
|
-
values = getValues(value.params, diffObj);
|
|
607
|
-
} else if ((typeof today === 'undefined' ? 'undefined' : _typeof(today)) === 'object') {
|
|
608
|
-
key = today.key;
|
|
609
|
-
values = getValues(today.params, diffObj);
|
|
610
|
-
isSuffixEnable = true;
|
|
611
|
-
} else if (typeof today === 'string') {
|
|
612
|
-
text = formatDate(toDateObj, today);
|
|
613
|
-
}
|
|
614
|
-
} else if (dateObj.getDate() < curDateObj.getDate()) {
|
|
615
|
-
if (typeof yesterday === 'function') {
|
|
616
|
-
var value = yesterday(diffObj1);
|
|
617
|
-
key = value.key;
|
|
618
|
-
values = getValues(value.params, diffObj);
|
|
619
|
-
} else if ((typeof yesterday === 'undefined' ? 'undefined' : _typeof(yesterday)) === 'object') {
|
|
620
|
-
key = yesterday.key;
|
|
621
|
-
values = getValues(yesterday.params, diffObj);
|
|
622
|
-
} else if (typeof yesterday === 'string') {
|
|
623
|
-
text = formatDate(toDateObj, yesterday);
|
|
624
|
-
}
|
|
625
|
-
} else if (dateObj.getDate() > curDateObj.getDate()) {
|
|
626
|
-
if (typeof tomorrow === 'function') {
|
|
627
|
-
var value = tomorrow(diffObj1);
|
|
628
|
-
key = value.key;
|
|
629
|
-
text = getValues(value.params, diffObj);
|
|
630
|
-
} else if ((typeof tomorrow === 'undefined' ? 'undefined' : _typeof(tomorrow)) === 'object') {
|
|
631
|
-
key = tomorrow.key;
|
|
632
|
-
values = getValues(tomorrow.params, diffObj);
|
|
633
|
-
} else if (typeof tomorrow === 'string') {
|
|
634
|
-
text = formatDate(toDateObj, tomorrow);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
} else {
|
|
638
|
-
var value = others(diffObj1);
|
|
639
|
-
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
|
|
640
|
-
key = value.key;
|
|
641
|
-
values = getValues(value.params, diffObj);
|
|
642
|
-
isSuffixEnable = true;
|
|
643
|
-
} else if (typeof value === 'string') {
|
|
644
|
-
text = formatDate(toDateObj, value);
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
var i18nText = isSuffixEnable && suffix !== '' ? key + '.' + suffix : key;
|
|
649
|
-
var titleFormated = titleString === undefined ? formatDate(to, titleFormat) : titleString;
|
|
650
|
-
return { formatedDate: text, values: values, i18nText: i18nText, title: titleFormated };
|
|
543
|
+
return suffix;
|
|
651
544
|
}
|