pacc 6.2.1 → 6.3.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/README.md CHANGED
@@ -102,13 +102,15 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
102
102
  * [Parameters](#parameters-11)
103
103
  * [getAttributeAndOperator](#getattributeandoperator)
104
104
  * [Parameters](#parameters-12)
105
- * [parseTime](#parsetime)
105
+ * [parseDuration](#parseduration)
106
106
  * [Parameters](#parameters-13)
107
+ * [formatDuration](#formatduration)
108
+ * [Parameters](#parameters-14)
107
109
  * [lookup](#lookup)
108
110
  * [Token](#token)
109
111
  * [Properties](#properties-1)
110
112
  * [createToken](#createtoken)
111
- * [Parameters](#parameters-14)
113
+ * [Parameters](#parameters-15)
112
114
  * [PLUS](#plus)
113
115
  * [MINUS](#minus)
114
116
  * [STAR](#star)
@@ -518,13 +520,25 @@ The name may be a property path like 'a.b.c <='.
518
520
 
519
521
  Returns **\[any, [Token](#token)]** value associated with the given property name
520
522
 
521
- ## parseTime
523
+ ## parseDuration
524
+
525
+ Convert duration formatted string into number of seconds.
526
+
527
+ Convert duration formatted string into number of seconds.
522
528
 
523
529
  ### Parameters
524
530
 
525
531
  * `value` **([number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))**&#x20;
526
532
 
527
- Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**&#x20;
533
+ Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** seconds
534
+
535
+ ## formatDuration
536
+
537
+ ### Parameters
538
+
539
+ * `seconds` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**&#x20;
540
+
541
+ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** formatted duration
528
542
 
529
543
  ## lookup
530
544
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "6.2.1",
3
+ "version": "6.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
package/src/time.mjs CHANGED
@@ -70,3 +70,35 @@ export function formatDuration(seconds) {
70
70
 
71
71
  return out.join(" ");
72
72
  }
73
+
74
+ const durationsISO = [
75
+ [86400, "D"],
76
+ [3600, "H"],
77
+ [60, "M"],
78
+ [1, "S"]
79
+ ];
80
+
81
+ /**
82
+ *
83
+ * @param {number} seconds
84
+ * @returns {string} formatted duration
85
+ */
86
+ export function formatDurationISO(seconds) {
87
+ let out = "P";
88
+ let t = false;
89
+
90
+ for (const d of durationsISO) {
91
+ if (seconds < 86400 && !t) {
92
+ out += "T";
93
+ t = true;
94
+ }
95
+
96
+ const n = Math.floor(seconds / Number(d[0]));
97
+ if (n > 0) {
98
+ out += `${n}${d[1]}`;
99
+ seconds -= n * Number(d[0]);
100
+ }
101
+ }
102
+
103
+ return out;
104
+ }
package/types/time.d.mts CHANGED
@@ -10,3 +10,9 @@ export function parseDuration(value: number | string): number;
10
10
  * @returns {string} formatted duration
11
11
  */
12
12
  export function formatDuration(seconds: number): string;
13
+ /**
14
+ *
15
+ * @param {number} seconds
16
+ * @returns {string} formatted duration
17
+ */
18
+ export function formatDurationISO(seconds: number): string;