@leancodepl/api-date-utils 9.6.4 → 9.6.6
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 +4 -4
- package/index.cjs.js +5 -5
- package/index.esm.js +5 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -54,11 +54,11 @@ console.log(result.values.milliseconds) // 123
|
|
|
54
54
|
import { parseApiTimeSpan } from "@leancodepl/api-date-utils"
|
|
55
55
|
|
|
56
56
|
const calculateTotalMilliseconds = (timespan: ApiTimeSpan) => {
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
const parsed = parseApiTimeSpan(timespan)
|
|
58
|
+
const { days, hours, minutes, seconds, milliseconds } = parsed.values
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
const total = days * 86400000 + hours * 3600000 + minutes * 60000 + seconds * 1000 + milliseconds
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
return parsed.sign === "-" ? -total : total
|
|
63
63
|
}
|
|
64
64
|
```
|
package/index.cjs.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
const parseIntMatched = (value)=>parseInt(value != null ? value : "0");
|
|
4
4
|
/**
|
|
5
5
|
* Parses ApiTimeSpan string into structured time components.
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* Extracts sign, days, hours, minutes, seconds, and milliseconds from
|
|
8
8
|
* ApiTimeSpan string format using regex pattern matching.
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
10
|
* @param timespan - The ApiTimeSpan string to parse
|
|
11
11
|
* @returns Object with sign and time component values
|
|
12
12
|
* @example
|
|
@@ -16,9 +16,9 @@ const parseIntMatched = (value)=>parseInt(value != null ? value : "0");
|
|
|
16
16
|
* ```
|
|
17
17
|
*/ function parseApiTimeSpan(timespan) {
|
|
18
18
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
* This regex returns tuple of matched strings (either of string type or undefined) and default match function parameters
|
|
20
|
+
* following [timeSpan, sign, days, hours, minutes, seconds, milliseconds, index of search at which the result was found, input (search string), groups] schema
|
|
21
|
+
*/ const matched = timespan.match(/^(-)?([0-9]+)?\.?([0-9]{2}):([0-9]{2}):([0-9]{2})\.?([0-9]{3})?$/);
|
|
22
22
|
return {
|
|
23
23
|
sign: matched == null ? void 0 : matched[1],
|
|
24
24
|
values: {
|
package/index.esm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const parseIntMatched = (value)=>parseInt(value != null ? value : "0");
|
|
2
2
|
/**
|
|
3
3
|
* Parses ApiTimeSpan string into structured time components.
|
|
4
|
-
*
|
|
4
|
+
*
|
|
5
5
|
* Extracts sign, days, hours, minutes, seconds, and milliseconds from
|
|
6
6
|
* ApiTimeSpan string format using regex pattern matching.
|
|
7
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* @param timespan - The ApiTimeSpan string to parse
|
|
9
9
|
* @returns Object with sign and time component values
|
|
10
10
|
* @example
|
|
@@ -14,9 +14,9 @@ const parseIntMatched = (value)=>parseInt(value != null ? value : "0");
|
|
|
14
14
|
* ```
|
|
15
15
|
*/ function parseApiTimeSpan(timespan) {
|
|
16
16
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
* This regex returns tuple of matched strings (either of string type or undefined) and default match function parameters
|
|
18
|
+
* following [timeSpan, sign, days, hours, minutes, seconds, milliseconds, index of search at which the result was found, input (search string), groups] schema
|
|
19
|
+
*/ const matched = timespan.match(/^(-)?([0-9]+)?\.?([0-9]{2}):([0-9]{2}):([0-9]{2})\.?([0-9]{3})?$/);
|
|
20
20
|
return {
|
|
21
21
|
sign: matched == null ? void 0 : matched[1],
|
|
22
22
|
values: {
|
package/package.json
CHANGED