@zohodesk/i18n 1.0.0-beta.3 → 1.0.0-beta.30
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 +116 -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 +59 -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 +82 -70
- 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 +34 -25
- 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
package/es/components/I18N.js
CHANGED
|
@@ -1,89 +1,74 @@
|
|
|
1
|
-
import _Object$assign from 'babel-runtime/core-js/object/assign';
|
|
2
|
-
import _Object$keys from 'babel-runtime/core-js/object/keys';
|
|
3
|
-
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
|
|
4
|
-
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
|
5
|
-
import _createClass from 'babel-runtime/helpers/createClass';
|
|
6
|
-
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
|
7
|
-
import _inherits from 'babel-runtime/helpers/inherits';
|
|
8
1
|
import React, { Children } from 'react';
|
|
9
2
|
import PropTypes from 'prop-types';
|
|
10
3
|
import { replaceI18NValuesWithRegex, unescapeUnicode } from '../utils';
|
|
11
4
|
import { HTMLPurifier } from '@zoho/SecurityJS';
|
|
12
5
|
import { I18NContext } from '../I18NContext';
|
|
6
|
+
export default class I18N extends React.Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.getI18NValue = this.getI18NValue.bind(this);
|
|
10
|
+
this.createElement = this.createElement.bind(this);
|
|
11
|
+
}
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
getI18NValue() {
|
|
14
|
+
const {
|
|
15
|
+
i18NKey: key,
|
|
16
|
+
values
|
|
17
|
+
} = this.props;
|
|
18
|
+
const {
|
|
19
|
+
i18n
|
|
20
|
+
} = this.context || {};
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
if (typeof i18n === 'undefined') {
|
|
23
|
+
return key;
|
|
24
|
+
}
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
_this.createElement = _this.createElement.bind(_this);
|
|
24
|
-
return _this;
|
|
25
|
-
}
|
|
26
|
+
let i18nStr = i18n[key];
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var _props = this.props,
|
|
31
|
-
key = _props.i18NKey,
|
|
32
|
-
values = _props.values;
|
|
28
|
+
if (i18nStr === undefined) {
|
|
29
|
+
return key;
|
|
30
|
+
}
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
|
|
33
|
+
return unescapeUnicode(i18nStr);
|
|
34
|
+
}
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (i18nStr === undefined) {
|
|
42
|
-
return key;
|
|
36
|
+
createElement() {
|
|
37
|
+
const props = Object.keys(this.props).reduce((result, nextKey) => {
|
|
38
|
+
if (nextKey != 'i18NKey' && nextKey != 'tag' && nextKey != 'values' && nextKey != 'isHtml' && nextKey != 'dataId') {
|
|
39
|
+
result[nextKey] = this.props[nextKey];
|
|
43
40
|
}
|
|
44
|
-
i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
|
|
45
|
-
return unescapeUnicode(i18nStr);
|
|
46
|
-
}
|
|
47
|
-
}, {
|
|
48
|
-
key: 'createElement',
|
|
49
|
-
value: function createElement() {
|
|
50
|
-
var _this2 = this;
|
|
51
41
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
result[nextKey] = _this2.props[nextKey];
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}, {});
|
|
58
|
-
//const child=this.getI18NValue();
|
|
59
|
-
if (this.props.dataId) {
|
|
60
|
-
props['data-id'] = this.props.dataId;
|
|
61
|
-
}
|
|
62
|
-
if (this.props.isHtml) {
|
|
63
|
-
var dangerouslySetInnerHTML = {
|
|
64
|
-
__html: HTMLPurifier.sanitize(this.getI18NValue())
|
|
65
|
-
};
|
|
42
|
+
return result;
|
|
43
|
+
}, {}); //const child=this.getI18NValue();
|
|
66
44
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
45
|
+
if (this.props.dataId) {
|
|
46
|
+
props['data-id'] = this.props.dataId;
|
|
47
|
+
props['data-test-id'] = this.props.dataId;
|
|
70
48
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
49
|
+
|
|
50
|
+
if (this.props.isHtml) {
|
|
51
|
+
let dangerouslySetInnerHTML = {
|
|
52
|
+
__html: HTMLPurifier.sanitize(this.getI18NValue())
|
|
53
|
+
};
|
|
54
|
+
return /*#__PURE__*/React.createElement(this.props.tag, Object.assign(props, {
|
|
55
|
+
dangerouslySetInnerHTML
|
|
56
|
+
}));
|
|
75
57
|
}
|
|
76
|
-
}]);
|
|
77
58
|
|
|
78
|
-
|
|
79
|
-
}
|
|
59
|
+
return /*#__PURE__*/React.createElement(this.props.tag, props, this.getI18NValue());
|
|
60
|
+
}
|
|
80
61
|
|
|
81
|
-
|
|
62
|
+
render() {
|
|
63
|
+
return this.createElement();
|
|
64
|
+
}
|
|
82
65
|
|
|
66
|
+
}
|
|
83
67
|
I18N.propTypes = {
|
|
84
68
|
i18NKey: PropTypes.string.isRequired,
|
|
85
69
|
isHtml: PropTypes.bool,
|
|
86
70
|
tag: PropTypes.string,
|
|
71
|
+
dataId: PropTypes.string,
|
|
87
72
|
values: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
|
|
88
73
|
};
|
|
89
74
|
I18N.defaultProps = {
|
|
@@ -1,116 +1,90 @@
|
|
|
1
|
-
import _Promise from 'babel-runtime/core-js/promise';
|
|
2
|
-
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
|
|
3
|
-
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
|
4
|
-
import _createClass from 'babel-runtime/helpers/createClass';
|
|
5
|
-
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
|
6
|
-
import _inherits from 'babel-runtime/helpers/inherits';
|
|
7
1
|
import React from 'react';
|
|
8
2
|
import PropTypes from 'prop-types';
|
|
9
3
|
import { getI18NValue, userDateFormat } from '../utils';
|
|
10
|
-
import {
|
|
11
|
-
import { createSelector } from 'reselect';
|
|
4
|
+
import { getI18NComponent } from '../utils/jsxTranslations';
|
|
12
5
|
import { I18NContext } from '../I18NContext';
|
|
6
|
+
const emptyObj = {};
|
|
13
7
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
var getTzData = createSelector([function (tzStr) {
|
|
19
|
-
return tzStr;
|
|
20
|
-
}], function (tzStr) {
|
|
21
|
-
return unpack(tzStr);
|
|
22
|
-
});
|
|
23
|
-
export var i18NProviderUtils = {
|
|
8
|
+
const dummy = (key, values) => key;
|
|
9
|
+
|
|
10
|
+
export const i18NProviderUtils = {
|
|
24
11
|
getI18NValue: dummy,
|
|
25
|
-
userDateFormat: dummy
|
|
12
|
+
userDateFormat: dummy,
|
|
13
|
+
getI18NComponent: dummy
|
|
26
14
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
function I18NProvider(props, context) {
|
|
32
|
-
_classCallCheck(this, I18NProvider);
|
|
33
|
-
|
|
34
|
-
var _this = _possibleConstructorReturn(this, (I18NProvider.__proto__ || _Object$getPrototypeOf(I18NProvider)).call(this, props, context));
|
|
35
|
-
|
|
15
|
+
export default class I18NProvider extends React.Component {
|
|
16
|
+
constructor(props, context) {
|
|
17
|
+
super(props, context);
|
|
36
18
|
i18NProviderUtils.getI18NValue = getI18NValue(props.i18n);
|
|
37
|
-
i18NProviderUtils.
|
|
38
|
-
|
|
19
|
+
i18NProviderUtils.getI18NComponent = getI18NComponent(props.i18n);
|
|
20
|
+
|
|
21
|
+
if (props.tzData) {
|
|
22
|
+
i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, props.tzData, props.timeFormat, props.datePattern, props.isEnabledCurrentYear);
|
|
23
|
+
}
|
|
39
24
|
}
|
|
40
25
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
26
|
+
componentDidUpdate(next) {
|
|
27
|
+
let {
|
|
28
|
+
i18n,
|
|
29
|
+
timeZone,
|
|
30
|
+
datePattern,
|
|
31
|
+
timeFormat,
|
|
32
|
+
direction,
|
|
33
|
+
onChange,
|
|
34
|
+
tzData
|
|
35
|
+
} = this.props;
|
|
45
36
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
onChange = _props.onChange,
|
|
54
|
-
tzData = _props.tzData;
|
|
37
|
+
if (i18n !== next.i18n || timeZone !== next.timeZone || datePattern !== next.datePattern || timeFormat !== next.timeFormat || direction !== next.direction || tzData !== next.tzData) {
|
|
38
|
+
this.promise = new Promise((res, rej) => {
|
|
39
|
+
this.resolve = res;
|
|
40
|
+
this.reject = rej;
|
|
41
|
+
}).then(() => {
|
|
42
|
+
i18NProviderUtils.getI18NValue = getI18NValue(nextProps.i18n);
|
|
43
|
+
i18NProviderUtils.getI18NComponent = getI18NComponent(nextProps.i18n);
|
|
55
44
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
_this2.reject = rej;
|
|
60
|
-
}).then(function () {
|
|
61
|
-
i18NProviderUtils.getI18NValue = getI18NValue(nextProps.i18n);
|
|
62
|
-
i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, unpack(tzData));
|
|
63
|
-
_this2.promise = null;
|
|
64
|
-
}, function () {
|
|
65
|
-
_this2.promise = null;
|
|
66
|
-
});
|
|
67
|
-
onChange && onChange(this.resolve, this.reject);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}, {
|
|
71
|
-
key: 'render',
|
|
72
|
-
value: function render() {
|
|
73
|
-
return React.createElement(
|
|
74
|
-
I18NContext.Provider,
|
|
75
|
-
{
|
|
76
|
-
value: {
|
|
77
|
-
i18n: this.props.i18n,
|
|
78
|
-
direction: this.props.direction,
|
|
79
|
-
timeZone: this.props.timeZone,
|
|
80
|
-
tzData: getTzData(this.props.tzData),
|
|
81
|
-
datePattern: this.props.datePattern,
|
|
82
|
-
timeFormat: this.props.timeFormat,
|
|
83
|
-
dateTimeFormat: this.props.dateTimeFormat
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
this.props.children
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
}]);
|
|
45
|
+
if (props.tzData) {
|
|
46
|
+
i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, props.tzData, props.timeFormat, props.datePattern, this.props.isEnabledCurrentYear);
|
|
47
|
+
}
|
|
90
48
|
|
|
91
|
-
|
|
92
|
-
}(
|
|
93
|
-
|
|
94
|
-
|
|
49
|
+
this.promise = null;
|
|
50
|
+
}, () => {
|
|
51
|
+
this.promise = null;
|
|
52
|
+
});
|
|
53
|
+
onChange && onChange(this.resolve, this.reject);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
95
56
|
|
|
57
|
+
render() {
|
|
58
|
+
return /*#__PURE__*/React.createElement(I18NContext.Provider, {
|
|
59
|
+
value: {
|
|
60
|
+
i18n: this.props.i18n,
|
|
61
|
+
direction: this.props.direction,
|
|
62
|
+
timeZone: this.props.timeZone,
|
|
63
|
+
datePattern: this.props.datePattern,
|
|
64
|
+
timeFormat: this.props.timeFormat,
|
|
65
|
+
isEnabledCurrentYear: this.props.isEnabledCurrentYear,
|
|
66
|
+
tzData: this.props.tzData
|
|
67
|
+
}
|
|
68
|
+
}, this.props.children);
|
|
69
|
+
}
|
|
96
70
|
|
|
71
|
+
}
|
|
97
72
|
I18NProvider.defaultProps = {
|
|
98
73
|
i18n: emptyObj,
|
|
99
74
|
timeZone: '',
|
|
100
75
|
datePattern: '',
|
|
101
76
|
timeFormat: '',
|
|
102
|
-
|
|
77
|
+
isEnabledCurrentYear: '',
|
|
103
78
|
direction: 'ltr'
|
|
104
79
|
};
|
|
105
|
-
|
|
106
80
|
I18NProvider.propTypes = {
|
|
107
81
|
children: PropTypes.element.isRequired,
|
|
108
82
|
datePattern: PropTypes.string,
|
|
109
|
-
|
|
83
|
+
isEnabledCurrentYear: PropTypes.string,
|
|
110
84
|
direction: PropTypes.string,
|
|
111
85
|
i18n: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
|
112
86
|
onChange: PropTypes.func,
|
|
113
87
|
timeFormat: PropTypes.string,
|
|
114
88
|
timeZone: PropTypes.string,
|
|
115
|
-
tzData: PropTypes.
|
|
89
|
+
tzData: PropTypes.object
|
|
116
90
|
};
|
|
@@ -1,57 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
|
4
|
-
import _createClass from 'babel-runtime/helpers/createClass';
|
|
5
|
-
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
|
6
|
-
import _inherits from 'babel-runtime/helpers/inherits';
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
7
3
|
import React from 'react';
|
|
8
4
|
import PropTypes from 'prop-types';
|
|
9
5
|
import FormatText from './FormatText';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
value = _props.value;
|
|
28
|
-
|
|
29
|
-
var key = '',
|
|
30
|
-
values = '';
|
|
31
|
-
if (value > 1) {
|
|
32
|
-
key = many;
|
|
33
|
-
} else if (value == 1) {
|
|
34
|
-
key = one;
|
|
35
|
-
} else if (value == 0) {
|
|
36
|
-
key = zero;
|
|
37
|
-
}
|
|
38
|
-
values = '' + value;
|
|
39
|
-
|
|
40
|
-
return React.createElement(FormatText, _extends({}, this.props, {
|
|
41
|
-
i18NKey: key,
|
|
42
|
-
values: values,
|
|
43
|
-
one: null,
|
|
44
|
-
many: null,
|
|
45
|
-
zero: null
|
|
46
|
-
}));
|
|
6
|
+
export default class PluralFormat extends React.Component {
|
|
7
|
+
render() {
|
|
8
|
+
const {
|
|
9
|
+
one,
|
|
10
|
+
many,
|
|
11
|
+
zero,
|
|
12
|
+
value
|
|
13
|
+
} = this.props;
|
|
14
|
+
let key = '',
|
|
15
|
+
values = '';
|
|
16
|
+
|
|
17
|
+
if (value > 1) {
|
|
18
|
+
key = many;
|
|
19
|
+
} else if (value == 1) {
|
|
20
|
+
key = one;
|
|
21
|
+
} else if (value == 0) {
|
|
22
|
+
key = zero;
|
|
47
23
|
}
|
|
48
|
-
}]);
|
|
49
24
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
25
|
+
values = `${value}`;
|
|
26
|
+
return /*#__PURE__*/React.createElement(FormatText, _extends({}, this.props, {
|
|
27
|
+
i18NKey: key,
|
|
28
|
+
values: values,
|
|
29
|
+
one: null,
|
|
30
|
+
many: null,
|
|
31
|
+
zero: null
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
54
34
|
|
|
35
|
+
}
|
|
55
36
|
PluralFormat.propTypes = {
|
|
56
37
|
many: PropTypes.string,
|
|
57
38
|
one: PropTypes.string,
|
|
@@ -1,91 +1,82 @@
|
|
|
1
|
-
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
|
|
2
|
-
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
|
3
|
-
import _createClass from 'babel-runtime/helpers/createClass';
|
|
4
|
-
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
|
5
|
-
import _inherits from 'babel-runtime/helpers/inherits';
|
|
6
1
|
import React, { Component } from 'react';
|
|
7
2
|
import PropTypes from 'prop-types';
|
|
8
3
|
import DateTimeDiffFormat from './DateTimeDiffFormat';
|
|
9
4
|
import { I18NContext } from '../I18NContext';
|
|
5
|
+
export default class UserTimeDiffFormat extends Component {
|
|
6
|
+
render() {
|
|
7
|
+
let currentTime = new Date();
|
|
8
|
+
let currentTimeUTCString = currentTime.toISOString();
|
|
9
|
+
let {
|
|
10
|
+
type,
|
|
11
|
+
page,
|
|
12
|
+
isNeedTime,
|
|
13
|
+
to,
|
|
14
|
+
today,
|
|
15
|
+
yesterday,
|
|
16
|
+
tomorrow,
|
|
17
|
+
others,
|
|
18
|
+
ago,
|
|
19
|
+
later,
|
|
20
|
+
format,
|
|
21
|
+
title,
|
|
22
|
+
className,
|
|
23
|
+
displayType,
|
|
24
|
+
dataId,
|
|
25
|
+
isOverdue,
|
|
26
|
+
isDateField
|
|
27
|
+
} = this.props;
|
|
28
|
+
let {
|
|
29
|
+
tzData,
|
|
30
|
+
timeFormat,
|
|
31
|
+
datePattern,
|
|
32
|
+
isEnabledCurrentYear
|
|
33
|
+
} = this.context || {};
|
|
10
34
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
_createClass(UserTimeDiffFormat, [{
|
|
21
|
-
key: 'render',
|
|
22
|
-
value: function render() {
|
|
23
|
-
var currentTime = new Date();
|
|
24
|
-
var currentTimeUTCString = currentTime.toISOString();
|
|
25
|
-
var _props = this.props,
|
|
26
|
-
type = _props.type,
|
|
27
|
-
to = _props.to,
|
|
28
|
-
today = _props.today,
|
|
29
|
-
yesterday = _props.yesterday,
|
|
30
|
-
tomorrow = _props.tomorrow,
|
|
31
|
-
others = _props.others,
|
|
32
|
-
ago = _props.ago,
|
|
33
|
-
later = _props.later,
|
|
34
|
-
format = _props.format,
|
|
35
|
-
title = _props.title,
|
|
36
|
-
className = _props.className,
|
|
37
|
-
displayType = _props.displayType,
|
|
38
|
-
dataId = _props.dataId,
|
|
39
|
-
isOverdue = _props.isOverdue;
|
|
40
|
-
|
|
41
|
-
var _ref = this.context || {},
|
|
42
|
-
tzData = _ref.tzData,
|
|
43
|
-
timeFormat = _ref.timeFormat,
|
|
44
|
-
datePattern = _ref.datePattern,
|
|
45
|
-
dateTimeFormat = _ref.dateTimeFormat,
|
|
46
|
-
timeZone = _ref.timeZone;
|
|
47
|
-
|
|
48
|
-
if (!format && !others) {
|
|
49
|
-
var pattern = displayType === 'date' ? datePattern : displayType === 'time' ? timeFormat : displayType === 'dateTime' ? dateTimeFormat : '';
|
|
50
|
-
format = function format() {
|
|
51
|
-
return pattern;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
var tz = tzData || timeZone;
|
|
56
|
-
|
|
57
|
-
return React.createElement(DateTimeDiffFormat, {
|
|
58
|
-
type: type,
|
|
59
|
-
from: currentTimeUTCString,
|
|
60
|
-
fromTzData: tz,
|
|
61
|
-
to: to,
|
|
62
|
-
toTzData: tz,
|
|
63
|
-
today: today,
|
|
64
|
-
yesterday: yesterday,
|
|
65
|
-
tomorrow: tomorrow,
|
|
66
|
-
others: others,
|
|
67
|
-
ago: ago,
|
|
68
|
-
later: later,
|
|
69
|
-
format: format,
|
|
70
|
-
title: title,
|
|
71
|
-
className: className,
|
|
72
|
-
dataId: dataId,
|
|
73
|
-
isOverdue: isOverdue
|
|
74
|
-
});
|
|
35
|
+
if (!format && !others) {
|
|
36
|
+
format = _ref => {
|
|
37
|
+
let {
|
|
38
|
+
dateTimeFormat,
|
|
39
|
+
dateFormat,
|
|
40
|
+
timeFormat
|
|
41
|
+
} = _ref;
|
|
42
|
+
displayType === 'dateTime' ? dateTimeFormat : displayType === 'date' ? dateFormat : timeFormat;
|
|
43
|
+
};
|
|
75
44
|
}
|
|
76
|
-
}]);
|
|
77
45
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
46
|
+
return /*#__PURE__*/React.createElement(DateTimeDiffFormat, {
|
|
47
|
+
type: type,
|
|
48
|
+
page: page,
|
|
49
|
+
isNeedTime: isNeedTime,
|
|
50
|
+
from: currentTimeUTCString,
|
|
51
|
+
fromTzData: tzData,
|
|
52
|
+
to: to,
|
|
53
|
+
toTzData: tzData,
|
|
54
|
+
today: today,
|
|
55
|
+
yesterday: yesterday,
|
|
56
|
+
tomorrow: tomorrow,
|
|
57
|
+
others: others,
|
|
58
|
+
ago: ago,
|
|
59
|
+
later: later,
|
|
60
|
+
format: format,
|
|
61
|
+
title: title,
|
|
62
|
+
className: className,
|
|
63
|
+
dataId: dataId,
|
|
64
|
+
isOverdue: isOverdue,
|
|
65
|
+
timeFormat: timeFormat,
|
|
66
|
+
datePattern: datePattern,
|
|
67
|
+
isEnabledCurrentYear: isEnabledCurrentYear,
|
|
68
|
+
isDateField: isDateField
|
|
69
|
+
});
|
|
70
|
+
}
|
|
82
71
|
|
|
72
|
+
}
|
|
83
73
|
UserTimeDiffFormat.propTypes = {
|
|
84
74
|
ago: PropTypes.string,
|
|
85
75
|
className: PropTypes.string,
|
|
86
76
|
dataId: PropTypes.string,
|
|
87
77
|
displayType: PropTypes.oneOf(['date', 'time', 'dateTime']),
|
|
88
78
|
format: PropTypes.func,
|
|
79
|
+
isDateField: PropTypes.bool,
|
|
89
80
|
later: PropTypes.string,
|
|
90
81
|
others: PropTypes.func,
|
|
91
82
|
title: PropTypes.string,
|