@cripty2001/utils 0.0.127 → 0.0.129
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 +12 -1
- package/package.json +1 -1
package/dist/react-whispr.js
CHANGED
|
@@ -166,12 +166,23 @@ 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 = (seconds) => {
|
|
170
|
+
if (seconds < 60)
|
|
171
|
+
return "second";
|
|
172
|
+
if (seconds < 3600)
|
|
173
|
+
return "minute";
|
|
174
|
+
if (seconds < 86400)
|
|
175
|
+
return "hour";
|
|
176
|
+
if (seconds < 604800)
|
|
177
|
+
return "day";
|
|
178
|
+
return "week";
|
|
179
|
+
};
|
|
169
180
|
const cb = (0, react_1.useCallback)((ts) => {
|
|
170
181
|
const now = currTs;
|
|
171
182
|
const then = ts instanceof Date ? ts.getTime() : ts;
|
|
172
183
|
const delta = then - now;
|
|
173
184
|
const seconds = Math.round(delta / 1000);
|
|
174
|
-
return rtf.format(seconds,
|
|
185
|
+
return rtf.format(seconds, getFormat(seconds));
|
|
175
186
|
}, [currTs, rtf]);
|
|
176
187
|
return cb;
|
|
177
188
|
}
|
package/package.json
CHANGED