@zohodesk/i18n 1.0.0-beta.3 → 1.0.0-beta.31
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 +120 -2
- package/es/I18NContext.js +1 -2
- package/es/components/DateTimeDiffFormat.js +192 -200
- package/es/components/FormatText.js +4 -25
- package/es/components/HOCI18N.js +33 -45
- package/es/components/I18N.js +48 -63
- package/es/components/I18NProvider.js +60 -85
- package/es/components/PluralFormat.js +29 -48
- package/es/components/UserTimeDiffFormat.js +65 -74
- 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/index.js +2 -6
- package/es/utils/__tests__/jsxTranslations.spec.js +174 -0
- package/es/utils/index.js +592 -0
- package/es/utils/jsxTranslations.js +193 -0
- package/lib/I18NContext.js +6 -6
- package/lib/components/DateTimeDiffFormat.js +151 -123
- package/lib/components/FormatText.js +32 -22
- package/lib/components/HOCI18N.js +47 -23
- package/lib/components/I18N.js +62 -36
- package/lib/components/I18NProvider.js +85 -72
- package/lib/components/PluralFormat.js +42 -32
- package/lib/components/UserTimeDiffFormat.js +79 -56
- 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/index.js +85 -110
- package/lib/utils/__tests__/jsxTranslations.spec.js +183 -0
- package/lib/utils/index.js +658 -0
- package/lib/utils/jsxTranslations.js +242 -0
- package/package.json +3 -2
- package/src/components/DateTimeDiffFormat.js +86 -55
- package/src/components/I18N.js +2 -0
- package/src/components/I18NProvider.js +44 -33
- package/src/components/UserTimeDiffFormat.js +24 -18
- package/src/index.js +7 -9
- package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
- package/src/utils/index.js +632 -0
- package/src/utils/jsxTranslations.js +180 -0
- package/es/components/NewDateFormat.js +0 -50
- package/es/offset.js +0 -629
- package/es/timezones.js +0 -118
- package/es/utils.js +0 -621
- package/lib/components/NewDateFormat.js +0 -68
- package/lib/offset.js +0 -634
- package/lib/timezones.js +0 -129
- package/lib/utils.js +0 -651
- package/src/components/NewDateFormat.js +0 -60
- package/src/offset.js +0 -629
- package/src/timezones.js +0 -113
- package/src/utils.js +0 -648
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { unescapeUnicode } from './index';
|
|
3
|
+
export function splitMatchedExp(_ref) {
|
|
4
|
+
let {
|
|
5
|
+
expression,
|
|
6
|
+
charLenToOmit,
|
|
7
|
+
string
|
|
8
|
+
} = _ref;
|
|
9
|
+
let splitString = string.split(new RegExp(expression, 'g'));
|
|
10
|
+
let matchedExpAll = string.matchAll(new RegExp(expression, 'g'));
|
|
11
|
+
let matchedExpKeys = [];
|
|
12
|
+
|
|
13
|
+
for (let match of matchedExpAll) {
|
|
14
|
+
const value = match[0];
|
|
15
|
+
matchedExpKeys.push(value.substring(charLenToOmit, value.length - charLenToOmit));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
splitString,
|
|
20
|
+
matchedExpKeys
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function generateChildren(_ref2) {
|
|
24
|
+
let {
|
|
25
|
+
children,
|
|
26
|
+
child
|
|
27
|
+
} = _ref2;
|
|
28
|
+
let newChildren = [],
|
|
29
|
+
stringPlaceHolders = {};
|
|
30
|
+
|
|
31
|
+
const handleString = string => {
|
|
32
|
+
if (string) {
|
|
33
|
+
let {
|
|
34
|
+
splitString,
|
|
35
|
+
matchedExpKeys
|
|
36
|
+
} = splitMatchedExp({
|
|
37
|
+
expression: '{[0-9]+?}',
|
|
38
|
+
charLenToOmit: 1,
|
|
39
|
+
string
|
|
40
|
+
});
|
|
41
|
+
stringPlaceHolders[newChildren.length] = matchedExpKeys;
|
|
42
|
+
newChildren.push(splitString);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
let {
|
|
47
|
+
splitString: splitChild,
|
|
48
|
+
matchedExpKeys: childrenKeys
|
|
49
|
+
} = splitMatchedExp({
|
|
50
|
+
expression: '<[A-Za-z0-9]+?>',
|
|
51
|
+
charLenToOmit: 1,
|
|
52
|
+
string: child
|
|
53
|
+
});
|
|
54
|
+
childrenKeys.forEach((childKey, childIndex) => {
|
|
55
|
+
const matchedChild = splitChild[childIndex];
|
|
56
|
+
handleString(matchedChild);
|
|
57
|
+
newChildren.push(children[childKey]);
|
|
58
|
+
});
|
|
59
|
+
handleString(splitChild[childrenKeys.length]);
|
|
60
|
+
return {
|
|
61
|
+
newChildren,
|
|
62
|
+
stringPlaceHolders
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export function createElement() {
|
|
66
|
+
let {
|
|
67
|
+
componentId,
|
|
68
|
+
children = [],
|
|
69
|
+
stringPlaceHolders = {}
|
|
70
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
71
|
+
return function () {
|
|
72
|
+
let {
|
|
73
|
+
components = {},
|
|
74
|
+
values = []
|
|
75
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
76
|
+
const {
|
|
77
|
+
type = React.Fragment,
|
|
78
|
+
props
|
|
79
|
+
} = components[componentId] || {};
|
|
80
|
+
const childElements = children.map((child, index) => {
|
|
81
|
+
if (typeof child === 'function') {
|
|
82
|
+
return child({
|
|
83
|
+
components,
|
|
84
|
+
values
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let string = '',
|
|
89
|
+
stringIndex = 0;
|
|
90
|
+
(stringPlaceHolders[index] || []).map((stringId, index) => {
|
|
91
|
+
if (child[index]) {
|
|
92
|
+
string += child[index];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
string += values[stringId];
|
|
96
|
+
stringIndex++;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
if (child[stringIndex]) {
|
|
100
|
+
string += child[stringIndex];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return string;
|
|
104
|
+
});
|
|
105
|
+
return /*#__PURE__*/React.createElement(type, props, ...childElements);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
;
|
|
109
|
+
export function replaceWithComponentPlaceHolder(_ref3) {
|
|
110
|
+
let {
|
|
111
|
+
componentId,
|
|
112
|
+
i18nKey,
|
|
113
|
+
childrenLength
|
|
114
|
+
} = _ref3;
|
|
115
|
+
const closingTagIndex = i18nKey.indexOf(`</${componentId}>`);
|
|
116
|
+
const childWithOpenTag = i18nKey.substring(0, closingTagIndex);
|
|
117
|
+
const openTagIndex = childWithOpenTag.lastIndexOf(`<${componentId}>`);
|
|
118
|
+
return i18nKey.substring(0, openTagIndex) + `<0${childrenLength}${componentId}>` + i18nKey.substring(closingTagIndex + `${componentId}`.length + 3);
|
|
119
|
+
}
|
|
120
|
+
export function prepareI18NFunc() {
|
|
121
|
+
let {
|
|
122
|
+
i18nKey,
|
|
123
|
+
children = {}
|
|
124
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
125
|
+
const componentIdMatch = i18nKey.match(/<\/[A-Za-z0-9]+?>/);
|
|
126
|
+
|
|
127
|
+
if (componentIdMatch) {
|
|
128
|
+
const componentId = componentIdMatch[0].substring(2, componentIdMatch[0].length - 1);
|
|
129
|
+
const childWithOpenTag = (i18nKey.match(new RegExp(`(.*?)(?=<\/${componentId}>)`)) || [])[0] || '';
|
|
130
|
+
const child = childWithOpenTag.split(`<${componentId}>`).pop();
|
|
131
|
+
const {
|
|
132
|
+
newChildren,
|
|
133
|
+
stringPlaceHolders
|
|
134
|
+
} = generateChildren({
|
|
135
|
+
children,
|
|
136
|
+
child
|
|
137
|
+
});
|
|
138
|
+
const childrenLength = Object.keys(children).length;
|
|
139
|
+
children[`0${childrenLength}${componentId}`] = createElement({
|
|
140
|
+
componentId,
|
|
141
|
+
children: newChildren,
|
|
142
|
+
stringPlaceHolders
|
|
143
|
+
});
|
|
144
|
+
i18nKey = replaceWithComponentPlaceHolder({
|
|
145
|
+
componentId,
|
|
146
|
+
i18nKey,
|
|
147
|
+
childrenLength
|
|
148
|
+
});
|
|
149
|
+
return prepareI18NFunc({
|
|
150
|
+
i18nKey,
|
|
151
|
+
children
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const {
|
|
156
|
+
newChildren,
|
|
157
|
+
stringPlaceHolders
|
|
158
|
+
} = generateChildren({
|
|
159
|
+
child: i18nKey,
|
|
160
|
+
children
|
|
161
|
+
});
|
|
162
|
+
return createElement({
|
|
163
|
+
componentId: -1,
|
|
164
|
+
children: newChildren,
|
|
165
|
+
stringPlaceHolders
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
export function getI18NComponent(i18n) {
|
|
169
|
+
if (typeof i18n === 'undefined') {
|
|
170
|
+
return key => key;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return key => {
|
|
174
|
+
let i18nStr = i18n[key];
|
|
175
|
+
|
|
176
|
+
if (i18nStr === undefined) {
|
|
177
|
+
return key;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (typeof i18nStr === 'string') {
|
|
181
|
+
i18nStr = unescapeUnicode(i18nStr);
|
|
182
|
+
const value = prepareI18NFunc({
|
|
183
|
+
i18nKey: i18nStr
|
|
184
|
+
});
|
|
185
|
+
window.loadI18nChunk && window.loadI18nChunk({
|
|
186
|
+
[key]: value
|
|
187
|
+
});
|
|
188
|
+
i18nStr = value;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return i18nStr;
|
|
192
|
+
};
|
|
193
|
+
}
|
package/lib/I18NContext.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.I18NContext =
|
|
6
|
+
exports.I18NContext = void 0;
|
|
7
7
|
|
|
8
|
-
var _react = require(
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
var I18NContext = /*#__PURE__*/_react["default"].createContext();
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
exports.I18NContext = I18NContext;
|
|
@@ -1,51 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports["default"] = void 0;
|
|
6
7
|
|
|
7
|
-
var
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
11
|
|
|
11
|
-
var
|
|
12
|
+
var _utils = require("../utils");
|
|
12
13
|
|
|
13
|
-
var
|
|
14
|
+
var _FormatText = _interopRequireDefault(require("./FormatText"));
|
|
14
15
|
|
|
15
|
-
var
|
|
16
|
+
var _datetimejs = _interopRequireDefault(require("@zohodesk/datetimejs"));
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
18
19
|
|
|
19
|
-
|
|
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); }
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
22
23
|
|
|
23
|
-
var
|
|
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); } }
|
|
24
25
|
|
|
25
|
-
function
|
|
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; }
|
|
26
27
|
|
|
27
|
-
function
|
|
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
|
+
|
|
30
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
31
|
+
|
|
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
|
+
|
|
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
|
+
|
|
36
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
28
37
|
|
|
29
|
-
function
|
|
38
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
30
39
|
|
|
31
|
-
function
|
|
40
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
32
41
|
|
|
33
|
-
var DateTimeDiffFormat = function (_React$Component) {
|
|
42
|
+
var DateTimeDiffFormat = /*#__PURE__*/function (_React$Component) {
|
|
34
43
|
_inherits(DateTimeDiffFormat, _React$Component);
|
|
35
44
|
|
|
45
|
+
var _super = _createSuper(DateTimeDiffFormat);
|
|
46
|
+
|
|
36
47
|
function DateTimeDiffFormat(props) {
|
|
37
|
-
|
|
48
|
+
var _this;
|
|
38
49
|
|
|
39
|
-
|
|
50
|
+
_classCallCheck(this, DateTimeDiffFormat);
|
|
40
51
|
|
|
41
|
-
_this
|
|
52
|
+
_this = _super.call(this, props);
|
|
53
|
+
_this.getSuffix = _this.getSuffix.bind(_assertThisInitialized(_this));
|
|
42
54
|
return _this;
|
|
43
55
|
}
|
|
44
56
|
|
|
45
57
|
_createClass(DateTimeDiffFormat, [{
|
|
46
|
-
key:
|
|
58
|
+
key: "getSuffix",
|
|
47
59
|
value: function getSuffix(min) {
|
|
48
|
-
var suffix
|
|
60
|
+
var suffix;
|
|
61
|
+
|
|
49
62
|
if (this.props.ago && min < 0) {
|
|
50
63
|
suffix = this.props.ago || '';
|
|
51
64
|
} else if (this.props.later || min > 0) {
|
|
@@ -53,38 +66,44 @@ var DateTimeDiffFormat = function (_React$Component) {
|
|
|
53
66
|
} else {
|
|
54
67
|
suffix = '';
|
|
55
68
|
}
|
|
69
|
+
|
|
56
70
|
return suffix;
|
|
57
71
|
}
|
|
58
72
|
}, {
|
|
59
|
-
key:
|
|
73
|
+
key: "render",
|
|
60
74
|
value: function render() {
|
|
61
|
-
var
|
|
62
|
-
type =
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
var _this$props = this.props,
|
|
76
|
+
type = _this$props.type,
|
|
77
|
+
page = _this$props.page,
|
|
78
|
+
isNeedTime = _this$props.isNeedTime,
|
|
79
|
+
from = _this$props.from,
|
|
80
|
+
fromTzData = _this$props.fromTzData,
|
|
81
|
+
to = _this$props.to,
|
|
82
|
+
toTzData = _this$props.toTzData,
|
|
83
|
+
today = _this$props.today,
|
|
84
|
+
yesterday = _this$props.yesterday,
|
|
85
|
+
tomorrow = _this$props.tomorrow,
|
|
86
|
+
others = _this$props.others,
|
|
87
|
+
format = _this$props.format,
|
|
88
|
+
dataId = _this$props.dataId,
|
|
89
|
+
_this$props$className = _this$props.className,
|
|
90
|
+
className = _this$props$className === void 0 ? null : _this$props$className,
|
|
91
|
+
_this$props$title = _this$props.title,
|
|
92
|
+
title = _this$props$title === void 0 ? null : _this$props$title,
|
|
93
|
+
isOverdue = _this$props.isOverdue,
|
|
94
|
+
timeFormat = _this$props.timeFormat,
|
|
95
|
+
datePattern = _this$props.datePattern,
|
|
96
|
+
isEnabledCurrentYear = _this$props.isEnabledCurrentYear,
|
|
97
|
+
isDateField = _this$props.isDateField;
|
|
98
|
+
|
|
99
|
+
var fromDateObj = _datetimejs["default"].toDate(_datetimejs["default"].tz.utcToTz(from, fromTzData)).getTime();
|
|
100
|
+
|
|
101
|
+
var toDateObj = _datetimejs["default"].toDate(isDateField ? to : _datetimejs["default"].tz.utcToTz(to, toTzData)).getTime();
|
|
82
102
|
|
|
83
103
|
var diffMin = new Date(to).getTime() - new Date(from).getTime();
|
|
84
104
|
var suffix = this.getSuffix(diffMin);
|
|
85
105
|
var diff = (0, _utils.getDiffObj)(diffMin);
|
|
86
106
|
var withInAWeak = diff.y === 0 && diff.yd <= 7;
|
|
87
|
-
|
|
88
107
|
var diffObj = {
|
|
89
108
|
h: diff.h,
|
|
90
109
|
m: diff.m,
|
|
@@ -100,13 +119,15 @@ var DateTimeDiffFormat = function (_React$Component) {
|
|
|
100
119
|
suffix: suffix
|
|
101
120
|
};
|
|
102
121
|
var diffObj1 = {
|
|
122
|
+
to: to,
|
|
103
123
|
type: type,
|
|
124
|
+
page: page,
|
|
125
|
+
isNeedTime: isNeedTime,
|
|
104
126
|
hours: diff.h,
|
|
105
127
|
minutes: diff.m,
|
|
106
128
|
seconds: diff.s,
|
|
107
129
|
years: diff.y,
|
|
108
130
|
yDays: diff.yd,
|
|
109
|
-
yMonth: diff.m,
|
|
110
131
|
isWithInAWeek: withInAWeak,
|
|
111
132
|
suffix: suffix,
|
|
112
133
|
crntDate: new Date(from).getDate(),
|
|
@@ -122,43 +143,53 @@ var DateTimeDiffFormat = function (_React$Component) {
|
|
|
122
143
|
tMinutes: new Date(to).getMinutes(),
|
|
123
144
|
tSeconds: new Date(to).getSeconds(),
|
|
124
145
|
betweenleepYears: (0, _utils.getLyears)(from, to),
|
|
125
|
-
isOverdue: isOverdue
|
|
126
|
-
|
|
146
|
+
isOverdue: isOverdue,
|
|
147
|
+
timeFormat: timeFormat,
|
|
148
|
+
datePattern: datePattern,
|
|
149
|
+
dateTimePattern: "".concat(datePattern, " ").concat(timeFormat)
|
|
150
|
+
}; //In if condition we'll remove year and set date format if the current year is not required
|
|
151
|
+
//In else part we'll set the date format as it is
|
|
152
|
+
|
|
153
|
+
if (isEnabledCurrentYear === true && diffObj1.years === 0 && diffObj1.tYear === diffObj1.crntYear) {
|
|
154
|
+
var dateFormat = (0, _utils.getDatePatternWithoutYear)(datePattern);
|
|
155
|
+
diffObj1.dateFormat = dateFormat;
|
|
156
|
+
diffObj1.dateTimeFormat = "".concat(dateFormat, " ").concat(timeFormat);
|
|
157
|
+
} else {
|
|
158
|
+
diffObj1.dateFormat = datePattern;
|
|
159
|
+
diffObj1.dateTimeFormat = "".concat(datePattern, " ").concat(timeFormat);
|
|
160
|
+
}
|
|
127
161
|
|
|
128
162
|
var key = '';
|
|
129
163
|
var values = [];
|
|
130
164
|
var text = null;
|
|
131
165
|
var isSuffixEnable = false;
|
|
166
|
+
|
|
132
167
|
if (format) {
|
|
133
|
-
var years
|
|
134
|
-
months = void 0,
|
|
135
|
-
days = void 0,
|
|
136
|
-
hours = void 0,
|
|
137
|
-
minutes = void 0,
|
|
138
|
-
seconds = void 0;
|
|
168
|
+
var years, months, days, hours, minutes, seconds;
|
|
139
169
|
years = diffObj1.years > 1 ? '2' : diffObj1.years;
|
|
140
|
-
|
|
141
170
|
days = diff.yd > 1 ? '2' : diff.yd;
|
|
142
171
|
hours = diffObj1.hours > 1 ? '2' : diffObj1.hours;
|
|
143
172
|
minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes;
|
|
144
|
-
|
|
145
173
|
var count = 0;
|
|
146
174
|
var pattern = [years, days, hours, minutes].reduce(function (res, next) {
|
|
147
175
|
if (count === 2) {
|
|
148
|
-
res = res
|
|
176
|
+
res = "".concat(res, "0");
|
|
149
177
|
} else if (next !== 0) {
|
|
150
178
|
count++;
|
|
151
179
|
res = res + next;
|
|
152
180
|
} else {
|
|
153
181
|
res = res + next;
|
|
154
182
|
}
|
|
183
|
+
|
|
155
184
|
return res;
|
|
156
185
|
}, '');
|
|
157
186
|
|
|
158
187
|
var _value = format(diffObj1, pattern);
|
|
159
|
-
|
|
188
|
+
|
|
189
|
+
if (_value && _typeof(_value) === 'object') {
|
|
160
190
|
key = _value.key;
|
|
161
191
|
values = (0, _utils.getValues)(_value.params, diffObj);
|
|
192
|
+
|
|
162
193
|
if (pattern.indexOf('00000') === 0) {
|
|
163
194
|
//suffix ignore for second hook
|
|
164
195
|
isSuffixEnable = false;
|
|
@@ -169,86 +200,83 @@ var DateTimeDiffFormat = function (_React$Component) {
|
|
|
169
200
|
text = (0, _utils.formatDate)(toDateObj, _value, diffObj1);
|
|
170
201
|
}
|
|
171
202
|
} else {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
text = (0, _utils.formatDate)(toDateObj, yesterday);
|
|
197
|
-
}
|
|
198
|
-
} else if (dateObj.getDate() > curDateObj.getDate()) {
|
|
199
|
-
if (typeof tomorrow === 'function') {
|
|
200
|
-
var value = tomorrow(diffObj1);
|
|
201
|
-
key = value.key;
|
|
202
|
-
text = (0, _utils.getValues)(value.params, diffObj);
|
|
203
|
-
} else if ((typeof tomorrow === 'undefined' ? 'undefined' : _typeof(tomorrow)) === 'object') {
|
|
204
|
-
key = tomorrow.key;
|
|
205
|
-
values = (0, _utils.getValues)(tomorrow.params, diffObj);
|
|
206
|
-
} else if (typeof tomorrow === 'string') {
|
|
207
|
-
text = (0, _utils.formatDate)(toDateObj, tomorrow);
|
|
203
|
+
var dateObj = new Date(toDateObj);
|
|
204
|
+
var curDateObj = new Date(fromDateObj);
|
|
205
|
+
var diffDayType = diffObj1.yDays; //In this condition, to calculate different days we have copied it from live --> diffDayType
|
|
206
|
+
|
|
207
|
+
if (isOverdue && dateObj.getDate() < curDateObj.getDate() && diffObj1.yDays == 0) {
|
|
208
|
+
diffDayType = -1;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (!isOverdue) {
|
|
212
|
+
var diffHr = dateObj.getHours() - curDateObj.getHours();
|
|
213
|
+
|
|
214
|
+
if (diffHr < 0) {
|
|
215
|
+
diffDayType += 1;
|
|
216
|
+
} else if (diffHr == 0) {
|
|
217
|
+
var diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
|
|
218
|
+
|
|
219
|
+
if (diffMins < 0) {
|
|
220
|
+
diffDayType += 1;
|
|
221
|
+
} else if (diffMins == 0) {
|
|
222
|
+
var diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
|
|
223
|
+
|
|
224
|
+
if (diffSec < 0) {
|
|
225
|
+
diffDayType += 1;
|
|
226
|
+
}
|
|
208
227
|
}
|
|
209
228
|
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
} else if (
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
|
|
232
|
+
if (dateObj.getDate() === curDateObj.getDate()) {
|
|
233
|
+
var value = today && today(diffObj1) || others(diffObj1);
|
|
234
|
+
text = (0, _utils.formatDate)(toDateObj, value);
|
|
235
|
+
} else if (dateObj.getMonth() === curDateObj.getMonth() && dateObj.getDate() < curDateObj.getDate() || dateObj.getMonth() < curDateObj.getMonth()) {
|
|
236
|
+
var value = yesterday && yesterday(diffObj1) || others(diffObj1);
|
|
237
|
+
text = (0, _utils.formatDate)(toDateObj, value);
|
|
238
|
+
} else if (!isOverdue && diff.y === 0 && diffDayType === 1) {
|
|
239
|
+
var value = tomorrow && tomorrow(diffObj1) || others(diffObj1);
|
|
217
240
|
text = (0, _utils.formatDate)(toDateObj, value);
|
|
218
241
|
}
|
|
242
|
+
} else {
|
|
243
|
+
var value = others(diffObj1);
|
|
244
|
+
text = (0, _utils.formatDate)(toDateObj, value);
|
|
219
245
|
}
|
|
220
246
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
247
|
+
|
|
248
|
+
return text ? /*#__PURE__*/_react["default"].createElement("span", {
|
|
249
|
+
className: className,
|
|
250
|
+
"data-title": title,
|
|
251
|
+
"data-id": dataId,
|
|
252
|
+
"data-test-id": dataId
|
|
253
|
+
}, text) : /*#__PURE__*/_react["default"].createElement(_FormatText["default"], {
|
|
254
|
+
i18NKey: isSuffixEnable && suffix !== '' ? "".concat(key, ".").concat(suffix) : key,
|
|
227
255
|
values: values,
|
|
228
256
|
className: className,
|
|
229
|
-
|
|
257
|
+
"data-title": title
|
|
230
258
|
});
|
|
231
259
|
}
|
|
232
260
|
}]);
|
|
233
261
|
|
|
234
262
|
return DateTimeDiffFormat;
|
|
235
|
-
}(
|
|
236
|
-
|
|
237
|
-
exports.default = DateTimeDiffFormat;
|
|
263
|
+
}(_react["default"].Component);
|
|
238
264
|
|
|
265
|
+
exports["default"] = DateTimeDiffFormat;
|
|
239
266
|
DateTimeDiffFormat.propTypes = {
|
|
240
|
-
ago:
|
|
241
|
-
className:
|
|
242
|
-
dataId:
|
|
243
|
-
format:
|
|
244
|
-
from:
|
|
245
|
-
fromTzData:
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
267
|
+
ago: _propTypes["default"].string,
|
|
268
|
+
className: _propTypes["default"].string,
|
|
269
|
+
dataId: _propTypes["default"].string,
|
|
270
|
+
format: _propTypes["default"].func,
|
|
271
|
+
from: _propTypes["default"].string,
|
|
272
|
+
fromTzData: _propTypes["default"].object,
|
|
273
|
+
isDateField: _propTypes["default"].bool,
|
|
274
|
+
later: _propTypes["default"].string,
|
|
275
|
+
others: _propTypes["default"].func,
|
|
276
|
+
title: _propTypes["default"].string,
|
|
277
|
+
to: _propTypes["default"].string,
|
|
278
|
+
toTzData: _propTypes["default"].object,
|
|
279
|
+
today: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object, _propTypes["default"].func]),
|
|
280
|
+
tomorrow: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object, _propTypes["default"].func]),
|
|
281
|
+
yesterday: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object, _propTypes["default"].func])
|
|
254
282
|
};
|