@zohodesk/i18n 1.0.0-beta.2 → 1.0.0-beta.21
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 -0
- package/es/I18NContext.js +1 -2
- package/es/components/DateTimeDiffFormat.js +192 -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/index.js +2 -6
- package/es/utils.js +250 -385
- package/lib/I18NContext.js +6 -6
- package/lib/components/DateTimeDiffFormat.js +167 -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/index.js +73 -119
- package/lib/utils.js +222 -329
- package/package.json +2 -2
- 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/es/components/I18N.js
CHANGED
|
@@ -1,85 +1,68 @@
|
|
|
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
|
-
return React.createElement(this.props.tag, props, this.getI18NValue());
|
|
45
|
+
if (this.props.dataId) {
|
|
46
|
+
props['data-id'] = this.props.dataId;
|
|
70
47
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
48
|
+
|
|
49
|
+
if (this.props.isHtml) {
|
|
50
|
+
let dangerouslySetInnerHTML = {
|
|
51
|
+
__html: HTMLPurifier.sanitize(this.getI18NValue())
|
|
52
|
+
};
|
|
53
|
+
return /*#__PURE__*/React.createElement(this.props.tag, Object.assign(props, {
|
|
54
|
+
dangerouslySetInnerHTML
|
|
55
|
+
}));
|
|
75
56
|
}
|
|
76
|
-
}]);
|
|
77
57
|
|
|
78
|
-
|
|
79
|
-
}
|
|
58
|
+
return /*#__PURE__*/React.createElement(this.props.tag, props, this.getI18NValue());
|
|
59
|
+
}
|
|
80
60
|
|
|
81
|
-
|
|
61
|
+
render() {
|
|
62
|
+
return this.createElement();
|
|
63
|
+
}
|
|
82
64
|
|
|
65
|
+
}
|
|
83
66
|
I18N.propTypes = {
|
|
84
67
|
i18NKey: PropTypes.string.isRequired,
|
|
85
68
|
isHtml: PropTypes.bool,
|
|
@@ -1,116 +1,86 @@
|
|
|
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 { unpack } from '../timezones';
|
|
11
|
-
import { createSelector } from 'reselect';
|
|
12
4
|
import { I18NContext } from '../I18NContext';
|
|
5
|
+
const emptyObj = {};
|
|
13
6
|
|
|
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 = {
|
|
7
|
+
const dummy = (key, values) => key;
|
|
8
|
+
|
|
9
|
+
export const i18NProviderUtils = {
|
|
24
10
|
getI18NValue: dummy,
|
|
25
11
|
userDateFormat: dummy
|
|
26
12
|
};
|
|
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
|
-
|
|
13
|
+
export default class I18NProvider extends React.Component {
|
|
14
|
+
constructor(props, context) {
|
|
15
|
+
super(props, context);
|
|
36
16
|
i18NProviderUtils.getI18NValue = getI18NValue(props.i18n);
|
|
37
|
-
|
|
38
|
-
|
|
17
|
+
|
|
18
|
+
if (props.tzData) {
|
|
19
|
+
i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, props.tzData, props.timeFormat, props.datePattern, props.isEnabledCurrentYear);
|
|
20
|
+
}
|
|
39
21
|
}
|
|
40
22
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
23
|
+
componentDidUpdate(next) {
|
|
24
|
+
let {
|
|
25
|
+
i18n,
|
|
26
|
+
timeZone,
|
|
27
|
+
datePattern,
|
|
28
|
+
timeFormat,
|
|
29
|
+
direction,
|
|
30
|
+
onChange,
|
|
31
|
+
tzData
|
|
32
|
+
} = this.props;
|
|
45
33
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
direction = _props.direction,
|
|
53
|
-
onChange = _props.onChange,
|
|
54
|
-
tzData = _props.tzData;
|
|
34
|
+
if (i18n !== next.i18n || timeZone !== next.timeZone || datePattern !== next.datePattern || timeFormat !== next.timeFormat || direction !== next.direction || tzData !== next.tzData) {
|
|
35
|
+
this.promise = new Promise((res, rej) => {
|
|
36
|
+
this.resolve = res;
|
|
37
|
+
this.reject = rej;
|
|
38
|
+
}).then(() => {
|
|
39
|
+
i18NProviderUtils.getI18NValue = getI18NValue(nextProps.i18n);
|
|
55
40
|
|
|
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
|
-
}]);
|
|
41
|
+
if (props.tzData) {
|
|
42
|
+
i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, props.tzData, props.timeFormat, props.datePattern, this.props.isEnabledCurrentYear);
|
|
43
|
+
}
|
|
90
44
|
|
|
91
|
-
|
|
92
|
-
}(
|
|
93
|
-
|
|
94
|
-
|
|
45
|
+
this.promise = null;
|
|
46
|
+
}, () => {
|
|
47
|
+
this.promise = null;
|
|
48
|
+
});
|
|
49
|
+
onChange && onChange(this.resolve, this.reject);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
95
52
|
|
|
53
|
+
render() {
|
|
54
|
+
return /*#__PURE__*/React.createElement(I18NContext.Provider, {
|
|
55
|
+
value: {
|
|
56
|
+
i18n: this.props.i18n,
|
|
57
|
+
direction: this.props.direction,
|
|
58
|
+
timeZone: this.props.timeZone,
|
|
59
|
+
datePattern: this.props.datePattern,
|
|
60
|
+
timeFormat: this.props.timeFormat,
|
|
61
|
+
isEnabledCurrentYear: this.props.isEnabledCurrentYear,
|
|
62
|
+
tzData: this.props.tzData
|
|
63
|
+
}
|
|
64
|
+
}, this.props.children);
|
|
65
|
+
}
|
|
96
66
|
|
|
67
|
+
}
|
|
97
68
|
I18NProvider.defaultProps = {
|
|
98
69
|
i18n: emptyObj,
|
|
99
70
|
timeZone: '',
|
|
100
71
|
datePattern: '',
|
|
101
72
|
timeFormat: '',
|
|
102
|
-
|
|
73
|
+
isEnabledCurrentYear: '',
|
|
103
74
|
direction: 'ltr'
|
|
104
75
|
};
|
|
105
|
-
|
|
106
76
|
I18NProvider.propTypes = {
|
|
107
77
|
children: PropTypes.element.isRequired,
|
|
108
78
|
datePattern: PropTypes.string,
|
|
109
|
-
|
|
79
|
+
isEnabledCurrentYear: PropTypes.string,
|
|
110
80
|
direction: PropTypes.string,
|
|
111
81
|
i18n: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
|
112
82
|
onChange: PropTypes.func,
|
|
113
83
|
timeFormat: PropTypes.string,
|
|
114
84
|
timeZone: PropTypes.string,
|
|
115
|
-
tzData: PropTypes.
|
|
85
|
+
tzData: PropTypes.object
|
|
116
86
|
};
|
|
@@ -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,87 +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
|
-
to = _props.to,
|
|
27
|
-
today = _props.today,
|
|
28
|
-
yesterday = _props.yesterday,
|
|
29
|
-
tomorrow = _props.tomorrow,
|
|
30
|
-
others = _props.others,
|
|
31
|
-
ago = _props.ago,
|
|
32
|
-
later = _props.later,
|
|
33
|
-
format = _props.format,
|
|
34
|
-
title = _props.title,
|
|
35
|
-
className = _props.className,
|
|
36
|
-
displayType = _props.displayType,
|
|
37
|
-
dataId = _props.dataId;
|
|
38
|
-
|
|
39
|
-
var _ref = this.context || {},
|
|
40
|
-
tzData = _ref.tzData,
|
|
41
|
-
timeFormat = _ref.timeFormat,
|
|
42
|
-
datePattern = _ref.datePattern,
|
|
43
|
-
dateTimeFormat = _ref.dateTimeFormat,
|
|
44
|
-
timeZone = _ref.timeZone;
|
|
45
|
-
|
|
46
|
-
if (!format && !others) {
|
|
47
|
-
var pattern = displayType === 'date' ? datePattern : displayType === 'time' ? timeFormat : displayType === 'dateTime' ? dateTimeFormat : '';
|
|
48
|
-
format = function format() {
|
|
49
|
-
return pattern;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
var tz = tzData || timeZone;
|
|
54
|
-
|
|
55
|
-
return React.createElement(DateTimeDiffFormat, {
|
|
56
|
-
from: currentTimeUTCString,
|
|
57
|
-
fromTzData: tz,
|
|
58
|
-
to: to,
|
|
59
|
-
toTzData: tz,
|
|
60
|
-
today: today,
|
|
61
|
-
yesterday: yesterday,
|
|
62
|
-
tomorrow: tomorrow,
|
|
63
|
-
others: others,
|
|
64
|
-
ago: ago,
|
|
65
|
-
later: later,
|
|
66
|
-
format: format,
|
|
67
|
-
title: title,
|
|
68
|
-
className: className,
|
|
69
|
-
dataId: dataId
|
|
70
|
-
});
|
|
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
|
+
};
|
|
71
44
|
}
|
|
72
|
-
}]);
|
|
73
45
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
+
}
|
|
78
71
|
|
|
72
|
+
}
|
|
79
73
|
UserTimeDiffFormat.propTypes = {
|
|
80
74
|
ago: PropTypes.string,
|
|
81
75
|
className: PropTypes.string,
|
|
82
76
|
dataId: PropTypes.string,
|
|
83
77
|
displayType: PropTypes.oneOf(['date', 'time', 'dateTime']),
|
|
84
78
|
format: PropTypes.func,
|
|
79
|
+
isDateField: PropTypes.bool,
|
|
85
80
|
later: PropTypes.string,
|
|
86
81
|
others: PropTypes.func,
|
|
87
82
|
title: PropTypes.string,
|