@amimpact/willy-utils 4.9.1 → 4.11.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amimpact/willy-utils",
3
- "version": "4.9.1",
3
+ "version": "4.11.0",
4
4
  "description": "Javascript utils",
5
5
  "scripts": {
6
6
  "publish:prerelease": "npm version prerelease --preid beta && npm publish --tag beta",
package/src/date.ts CHANGED
@@ -335,3 +335,52 @@ export const parseISODuration = (duration: string, options: parseISODurationOpti
335
335
 
336
336
  return durationObject;
337
337
  };
338
+ /**
339
+ * Format seconds to HH:MM
340
+ * @param {number} totalSeconds
341
+ */
342
+ export const formatSecondsToHumanReadableTime = (
343
+ totalSeconds: number,
344
+ format: String = 'HH:MM',
345
+ ) => {
346
+ // Bepaal of de tijd negatief is
347
+ const isNegative = totalSeconds < 0;
348
+
349
+ // Neem de absolute waarde voor de berekeningen
350
+ const absSeconds = Math.abs(totalSeconds);
351
+
352
+ // Helper functie om voorloopnullen toe te voegen
353
+ const pad = (num) => String(num).padStart(2, '0');
354
+
355
+ let formattedString = '';
356
+
357
+ switch (format) {
358
+ case 'HH:MM:SS': {
359
+ const hours = Math.floor(absSeconds / 3600);
360
+ const remainingSecondsAfterHours = absSeconds % 3600;
361
+ const minutes = Math.floor(remainingSecondsAfterHours / 60);
362
+ const seconds = remainingSecondsAfterHours % 60;
363
+ formattedString = `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
364
+ break;
365
+ }
366
+ case 'MM:SS': {
367
+ const minutes = Math.floor(absSeconds / 60);
368
+ const seconds = absSeconds % 60;
369
+ formattedString = `${pad(minutes)}:${pad(seconds)}`;
370
+ break;
371
+ }
372
+ case 'HH:MM':
373
+ default: {
374
+ const totalMinutes = Math.floor(absSeconds / 60);
375
+ const hours = Math.floor(totalMinutes / 60);
376
+ const minutes = totalMinutes % 60;
377
+ formattedString = `${pad(hours)}:${pad(minutes)}`;
378
+ break;
379
+ }
380
+ }
381
+
382
+ // Voeg het minteken toe als de oorspronkelijke waarde negatief was
383
+ const sign = isNegative ? '-' : '';
384
+
385
+ return `${sign}${formattedString}`;
386
+ };
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ import {
3
3
  formatCraftDate,
4
4
  formatDateFromNow,
5
5
  formatNewDate,
6
+ formatSecondsToHumanReadableTime,
6
7
  formatUTCDate,
7
8
  parseISODuration,
8
9
  } from './date';
@@ -47,6 +48,7 @@ export {
47
48
  convertObjectToFormData,
48
49
  formatDateFromNow,
49
50
  formatNewDate,
51
+ formatSecondsToHumanReadableTime,
50
52
  formatUTCDate,
51
53
  getNestedSet,
52
54
  getParents,