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