@arcblock/ux 2.1.51 → 2.1.54

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.
@@ -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' : 'zh-us';
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 = (0, _dayjs.default)(value).locale(localeOption).from(from, withoutSuffix);
101
+ relativeString = datetime.from(from, withoutSuffix);
95
102
  } else if (to) {
96
- relativeString = (0, _dayjs.default)(value).locale(localeOption).to(to, withoutSuffix);
103
+ relativeString = datetime.to(to, withoutSuffix);
97
104
  } else {
98
- relativeString = (0, _dayjs.default)(value).locale(localeOption).fromNow(withoutSuffix);
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.string
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: undefined
136
146
  };
package/lib/Util/index.js CHANGED
@@ -236,7 +236,7 @@ const createDateFormater = format => (date, _ref2) => {
236
236
 
237
237
  let instance = dateTool(date);
238
238
 
239
- if (typeof tz !== 'undefined') {
239
+ if (tz) {
240
240
  instance = instance.tz(tz);
241
241
  }
242
242
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.1.51",
3
+ "version": "2.1.54",
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": "fd1815a1cf5ad25d34017550fb4cd429afd7b375",
55
+ "gitHead": "a3907bf6904c52478a692d09ee0c4fc4fab7d42e",
56
56
  "dependencies": {
57
- "@arcblock/icons": "^2.1.51",
58
- "@arcblock/react-hooks": "^2.1.51",
57
+ "@arcblock/icons": "^2.1.54",
58
+ "@arcblock/react-hooks": "^2.1.54",
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' : 'zh-us';
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 = dayjs(value).locale(localeOption).from(from, withoutSuffix);
52
+ relativeString = datetime.from(from, withoutSuffix);
48
53
  } else if (to) {
49
- relativeString = dayjs(value).locale(localeOption).to(to, withoutSuffix);
54
+ relativeString = datetime.to(to, withoutSuffix);
50
55
  } else {
51
- relativeString = dayjs(value).locale(localeOption).fromNow(withoutSuffix);
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.string,
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: undefined,
86
93
  };
package/src/Util/index.js CHANGED
@@ -190,7 +190,7 @@ const createDateFormater =
190
190
 
191
191
  let instance = dateTool(date);
192
192
 
193
- if (typeof tz !== 'undefined') {
193
+ if (tz) {
194
194
  instance = instance.tz(tz);
195
195
  }
196
196