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