@arcblock/ux 2.1.51 → 2.1.52
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/lib/RelativeTime/index.js +19 -9
- package/package.json +4 -4
- package/src/RelativeTime/index.js +14 -7
|
@@ -27,7 +27,7 @@ var _Util = require("../Util");
|
|
|
27
27
|
|
|
28
28
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
29
29
|
|
|
30
|
-
const _excluded = ["value", "locale", "withoutSuffix", "from", "to", "type"];
|
|
30
|
+
const _excluded = ["value", "locale", "withoutSuffix", "from", "to", "type", "tz"];
|
|
31
31
|
|
|
32
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
33
|
|
|
@@ -79,7 +79,8 @@ function RelativeTime(_ref) {
|
|
|
79
79
|
withoutSuffix,
|
|
80
80
|
from,
|
|
81
81
|
to,
|
|
82
|
-
type
|
|
82
|
+
type,
|
|
83
|
+
tz
|
|
83
84
|
} = _ref,
|
|
84
85
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
85
86
|
|
|
@@ -87,19 +88,26 @@ function RelativeTime(_ref) {
|
|
|
87
88
|
return '-';
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
const localeOption = locale === 'zh' ? 'zh-cn' : '
|
|
91
|
+
const localeOption = locale === 'zh' ? 'zh-cn' : 'en-us';
|
|
92
|
+
const datetime = (0, _dayjs.default)(value).locale(localeOption);
|
|
93
|
+
|
|
94
|
+
if (tz) {
|
|
95
|
+
datetime.tz(tz);
|
|
96
|
+
}
|
|
97
|
+
|
|
91
98
|
let relativeString;
|
|
92
99
|
|
|
93
100
|
if (from) {
|
|
94
|
-
relativeString =
|
|
101
|
+
relativeString = datetime.from(from, withoutSuffix);
|
|
95
102
|
} else if (to) {
|
|
96
|
-
relativeString =
|
|
103
|
+
relativeString = datetime.to(to, withoutSuffix);
|
|
97
104
|
} else {
|
|
98
|
-
relativeString =
|
|
105
|
+
relativeString = datetime.fromNow(withoutSuffix);
|
|
99
106
|
}
|
|
100
107
|
|
|
101
108
|
const absoluteString = (0, _Util.formatToDatetime)(value, {
|
|
102
|
-
locale: localeOption
|
|
109
|
+
locale: localeOption,
|
|
110
|
+
tz
|
|
103
111
|
});
|
|
104
112
|
let innerContent = relativeString;
|
|
105
113
|
let popContent = absoluteString;
|
|
@@ -125,12 +133,14 @@ RelativeTime.propTypes = {
|
|
|
125
133
|
withoutSuffix: _propTypes.default.bool,
|
|
126
134
|
from: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
127
135
|
to: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
128
|
-
type: _propTypes.default.
|
|
136
|
+
type: _propTypes.default.oneOf(['relative', 'absolute']),
|
|
137
|
+
tz: _propTypes.default.string
|
|
129
138
|
};
|
|
130
139
|
RelativeTime.defaultProps = {
|
|
131
140
|
locale: 'en',
|
|
132
141
|
withoutSuffix: false,
|
|
133
142
|
from: '',
|
|
134
143
|
to: '',
|
|
135
|
-
type: 'relative'
|
|
144
|
+
type: 'relative',
|
|
145
|
+
tz: ''
|
|
136
146
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/ux",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.52",
|
|
4
4
|
"description": "Common used react components for arcblock products",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"react": ">=18.1.0",
|
|
53
53
|
"react-ga": "^2.7.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "f18933f9572861a3484438906614094b9497719e",
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@arcblock/icons": "^2.1.
|
|
58
|
-
"@arcblock/react-hooks": "^2.1.
|
|
57
|
+
"@arcblock/icons": "^2.1.52",
|
|
58
|
+
"@arcblock/react-hooks": "^2.1.52",
|
|
59
59
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
60
60
|
"@emotion/react": "^11.9.0",
|
|
61
61
|
"@emotion/styled": "^11.8.1",
|
|
@@ -34,24 +34,29 @@ dayjs.updateLocale('zh-cn', {
|
|
|
34
34
|
});
|
|
35
35
|
setDateTool(dayjs);
|
|
36
36
|
|
|
37
|
-
export default function RelativeTime({ value, locale, withoutSuffix, from, to, type, ...rest }) {
|
|
37
|
+
export default function RelativeTime({ value, locale, withoutSuffix, from, to, type, tz, ...rest }) {
|
|
38
38
|
if (!value) {
|
|
39
39
|
return '-';
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
const localeOption = locale === 'zh' ? 'zh-cn' : '
|
|
42
|
+
const localeOption = locale === 'zh' ? 'zh-cn' : 'en-us';
|
|
43
|
+
const datetime = dayjs(value).locale(localeOption);
|
|
44
|
+
|
|
45
|
+
if (tz) {
|
|
46
|
+
datetime.tz(tz);
|
|
47
|
+
}
|
|
43
48
|
|
|
44
49
|
let relativeString;
|
|
45
50
|
|
|
46
51
|
if (from) {
|
|
47
|
-
relativeString =
|
|
52
|
+
relativeString = datetime.from(from, withoutSuffix);
|
|
48
53
|
} else if (to) {
|
|
49
|
-
relativeString =
|
|
54
|
+
relativeString = datetime.to(to, withoutSuffix);
|
|
50
55
|
} else {
|
|
51
|
-
relativeString =
|
|
56
|
+
relativeString = datetime.fromNow(withoutSuffix);
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
const absoluteString = formatToDatetime(value, { locale: localeOption });
|
|
59
|
+
const absoluteString = formatToDatetime(value, { locale: localeOption, tz });
|
|
55
60
|
|
|
56
61
|
let innerContent = relativeString;
|
|
57
62
|
let popContent = absoluteString;
|
|
@@ -74,7 +79,8 @@ RelativeTime.propTypes = {
|
|
|
74
79
|
withoutSuffix: PropTypes.bool,
|
|
75
80
|
from: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
76
81
|
to: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
77
|
-
type: PropTypes.
|
|
82
|
+
type: PropTypes.oneOf(['relative', 'absolute']),
|
|
83
|
+
tz: PropTypes.string,
|
|
78
84
|
};
|
|
79
85
|
|
|
80
86
|
RelativeTime.defaultProps = {
|
|
@@ -83,4 +89,5 @@ RelativeTime.defaultProps = {
|
|
|
83
89
|
from: '',
|
|
84
90
|
to: '',
|
|
85
91
|
type: 'relative',
|
|
92
|
+
tz: '',
|
|
86
93
|
};
|