@hardlydifficult/date-time 1.0.8 → 1.0.10
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 +28 -34
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @hardlydifficult/date-time
|
|
2
2
|
|
|
3
|
-
A TypeScript
|
|
3
|
+
A TypeScript utility for converting time durations to milliseconds with strong typing.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -14,50 +14,44 @@ npm install @hardlydifficult/date-time
|
|
|
14
14
|
import { toMilliseconds, type TimeSpan } from "@hardlydifficult/date-time";
|
|
15
15
|
|
|
16
16
|
const duration: TimeSpan = { value: 2.5, unit: "minutes" };
|
|
17
|
-
const
|
|
18
|
-
// => 150000
|
|
17
|
+
const ms = toMilliseconds(duration); // 150_000
|
|
19
18
|
```
|
|
20
19
|
|
|
21
|
-
##
|
|
20
|
+
## TimeSpan Conversion
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
Converts a time duration to its equivalent in milliseconds using predefined unit multipliers.
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
### `TimeSpan` Interface
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
import { toMilliseconds, type TimeSpan } from "@hardlydifficult/date-time";
|
|
29
|
-
|
|
30
|
-
// Seconds
|
|
31
|
-
toMilliseconds({ value: 5, unit: "seconds" }); // => 5000
|
|
32
|
-
|
|
33
|
-
// Minutes
|
|
34
|
-
toMilliseconds({ value: 1.5, unit: "minutes" }); // => 90000
|
|
26
|
+
Represents a time duration with a numeric `value` and a `unit`.
|
|
35
27
|
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
| Field | Type | Description |
|
|
29
|
+
|-------|----------|----------------------|
|
|
30
|
+
| value | `number` | The numeric duration |
|
|
31
|
+
| unit | `TimeUnit` | The time unit |
|
|
38
32
|
|
|
39
|
-
|
|
40
|
-
toMilliseconds({ value: 1, unit: "days" }); // => 86400000
|
|
33
|
+
### `TimeUnit` Type
|
|
41
34
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
Supported time units:
|
|
36
|
+
- `"milliseconds"`
|
|
37
|
+
- `"seconds"`
|
|
38
|
+
- `"minutes"`
|
|
39
|
+
- `"hours"`
|
|
40
|
+
- `"days"`
|
|
45
41
|
|
|
46
|
-
###
|
|
42
|
+
### `toMilliseconds(timeSpan)`
|
|
47
43
|
|
|
48
|
-
|
|
44
|
+
Converts a `TimeSpan` to milliseconds.
|
|
49
45
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
| value | `number` | The numeric duration |
|
|
53
|
-
| unit | `TimeUnit` | The time unit (see below) |
|
|
46
|
+
```typescript
|
|
47
|
+
import { toMilliseconds } from "@hardlydifficult/date-time";
|
|
54
48
|
|
|
55
|
-
|
|
49
|
+
// Convert 2 hours
|
|
50
|
+
toMilliseconds({ value: 2, unit: "hours" }); // 7_200_000
|
|
56
51
|
|
|
57
|
-
|
|
52
|
+
// Convert 0.5 days
|
|
53
|
+
toMilliseconds({ value: 0.5, unit: "days" }); // 43_200_000
|
|
58
54
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- `"hours"`
|
|
63
|
-
- `"days"`
|
|
55
|
+
// Handle fractional values
|
|
56
|
+
toMilliseconds({ value: 1.5, unit: "minutes" }); // 90_000
|
|
57
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardlydifficult/date-time",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -20,5 +20,13 @@
|
|
|
20
20
|
},
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=18.0.0"
|
|
23
|
+
},
|
|
24
|
+
"type": "commonjs",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"require": "./dist/index.js"
|
|
30
|
+
}
|
|
23
31
|
}
|
|
24
32
|
}
|