@cripty2001/utils 0.0.132 → 0.0.133
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 +20 -12
- package/package.json +1 -1
package/dist/react-whispr.js
CHANGED
|
@@ -166,24 +166,32 @@ 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 = (
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
169
|
+
const getFormat = (diff) => {
|
|
170
|
+
const breakpoints = [
|
|
171
|
+
{ limit: 60, unit: "second" },
|
|
172
|
+
{ limit: 3600, unit: "minute" },
|
|
173
|
+
{ limit: 86400, unit: "hour" },
|
|
174
|
+
{ limit: 604800, unit: "day" },
|
|
175
|
+
];
|
|
176
|
+
for (const { limit, unit } of breakpoints) {
|
|
177
|
+
if (diff < limit)
|
|
178
|
+
return {
|
|
179
|
+
limit,
|
|
180
|
+
unit
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
limit: 2592000,
|
|
185
|
+
unit: "week"
|
|
186
|
+
};
|
|
180
187
|
};
|
|
181
188
|
const cb = (0, react_1.useCallback)((ts) => {
|
|
182
189
|
const now = currTs;
|
|
183
190
|
const then = ts instanceof Date ? ts.getTime() : ts;
|
|
184
191
|
const delta = then - now;
|
|
185
192
|
const seconds = Math.round(delta / 1000);
|
|
186
|
-
|
|
193
|
+
const { limit, unit } = getFormat(seconds);
|
|
194
|
+
return rtf.format(Math.floor(seconds / limit), unit);
|
|
187
195
|
}, [currTs, rtf]);
|
|
188
196
|
return cb;
|
|
189
197
|
}
|
package/package.json
CHANGED