@cripty2001/utils 0.0.134 → 0.0.135
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/dist/react-whispr.js +6 -3
- package/package.json +1 -1
package/dist/react-whispr.js
CHANGED
|
@@ -166,7 +166,8 @@ function useAsync(f, data, debouce = 200) {
|
|
|
166
166
|
function useRelTime(refresh = 1000) {
|
|
167
167
|
const currTs = useCurrentTimestamp(refresh);
|
|
168
168
|
const rtf = (0, react_1.useRef)(new Intl.RelativeTimeFormat(navigator.language, { numeric: "auto" })).current;
|
|
169
|
-
const getFormat = (
|
|
169
|
+
const getFormat = (_diff) => {
|
|
170
|
+
const diff = Math.abs(_diff);
|
|
170
171
|
const breakpoints = [
|
|
171
172
|
{ limit: 60, unit: "second" },
|
|
172
173
|
{ limit: 3600, unit: "minute" },
|
|
@@ -191,8 +192,10 @@ function useRelTime(refresh = 1000) {
|
|
|
191
192
|
const delta = then - now;
|
|
192
193
|
const seconds = Math.round(delta / 1000);
|
|
193
194
|
const { limit, unit } = getFormat(seconds);
|
|
194
|
-
|
|
195
|
-
|
|
195
|
+
const rounded = seconds > 0 ?
|
|
196
|
+
Math.floor(seconds / limit) :
|
|
197
|
+
Math.ceil(seconds / limit);
|
|
198
|
+
return rtf.format(rounded, unit);
|
|
196
199
|
}, [currTs, rtf]);
|
|
197
200
|
return cb;
|
|
198
201
|
}
|
package/package.json
CHANGED