@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.
@@ -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
- { limit: 60, unit: "second" },
173
- { limit: 3600, unit: "minute" },
174
- { limit: 86400, unit: "hour" },
175
- { limit: 604800, unit: "day" },
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
- limit,
196
+ base,
181
197
  unit
182
198
  };
183
199
  }
184
200
  return {
185
- limit: 2592000,
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 { limit, unit } = getFormat(seconds);
210
+ const { base, unit } = getFormat(seconds);
195
211
  const rounded = seconds > 0 ?
196
- Math.floor(seconds / limit) :
197
- Math.ceil(seconds / limit);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.135",
3
+ "version": "0.0.136",
4
4
  "description": "Internal Set of utils. If you need them use them, otherwise go to the next package ;)",
5
5
  "homepage": "https://github.com/cripty2001/utils#readme",
6
6
  "bugs": {