@cripty2001/utils 0.0.134 → 0.0.136
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 +31 -12
- package/package.json +1 -1
package/dist/react-whispr.js
CHANGED
|
@@ -166,22 +166,39 @@ 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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
{
|
|
173
|
+
base: 1,
|
|
174
|
+
limit: 60,
|
|
175
|
+
unit: "second"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
base: 60,
|
|
179
|
+
limit: 60,
|
|
180
|
+
unit: "minute"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
base: 60 * 60,
|
|
184
|
+
limit: 24,
|
|
185
|
+
unit: "hour"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
base: 60 * 60 * 24,
|
|
189
|
+
limit: 45,
|
|
190
|
+
unit: "day"
|
|
191
|
+
},
|
|
175
192
|
];
|
|
176
|
-
for (const { limit, unit } of breakpoints) {
|
|
177
|
-
if (diff < limit)
|
|
193
|
+
for (const { base, limit, unit } of breakpoints) {
|
|
194
|
+
if (diff < limit * base)
|
|
178
195
|
return {
|
|
179
|
-
|
|
196
|
+
base,
|
|
180
197
|
unit
|
|
181
198
|
};
|
|
182
199
|
}
|
|
183
200
|
return {
|
|
184
|
-
|
|
201
|
+
base: 60 * 60 * 24 * 7,
|
|
185
202
|
unit: "week"
|
|
186
203
|
};
|
|
187
204
|
};
|
|
@@ -190,9 +207,11 @@ function useRelTime(refresh = 1000) {
|
|
|
190
207
|
const then = ts instanceof Date ? ts.getTime() : ts;
|
|
191
208
|
const delta = then - now;
|
|
192
209
|
const seconds = Math.round(delta / 1000);
|
|
193
|
-
const {
|
|
194
|
-
|
|
195
|
-
|
|
210
|
+
const { base, unit } = getFormat(seconds);
|
|
211
|
+
const rounded = seconds > 0 ?
|
|
212
|
+
Math.floor(seconds / base) :
|
|
213
|
+
Math.ceil(seconds / base);
|
|
214
|
+
return rtf.format(rounded, unit);
|
|
196
215
|
}, [currTs, rtf]);
|
|
197
216
|
return cb;
|
|
198
217
|
}
|
package/package.json
CHANGED