@hardlydifficult/date-time 1.0.7 → 1.0.8
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 +30 -70
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @hardlydifficult/date-time
|
|
2
2
|
|
|
3
|
-
A TypeScript library for
|
|
3
|
+
A TypeScript library for representing time durations and converting them to milliseconds.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -14,90 +14,50 @@ 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
|
-
|
|
17
|
+
const milliseconds = toMilliseconds(duration);
|
|
18
|
+
// => 150000
|
|
18
19
|
```
|
|
19
20
|
|
|
20
|
-
## Time
|
|
21
|
+
## Time Duration Conversion
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
### toMilliseconds
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
Represents a time duration with a numeric `value` and a `unit`.
|
|
25
|
+
Converts a `TimeSpan` to its equivalent value in milliseconds.
|
|
27
26
|
|
|
28
27
|
```typescript
|
|
29
|
-
|
|
30
|
-
value: number;
|
|
31
|
-
unit: TimeUnit;
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
Where `TimeUnit` supports:
|
|
36
|
-
- `"milliseconds"`
|
|
37
|
-
- `"seconds"`
|
|
38
|
-
- `"minutes"`
|
|
39
|
-
- `"hours"`
|
|
40
|
-
- `"days"`
|
|
41
|
-
|
|
42
|
-
### toMilliseconds()
|
|
28
|
+
import { toMilliseconds, type TimeSpan } from "@hardlydifficult/date-time";
|
|
43
29
|
|
|
44
|
-
|
|
30
|
+
// Seconds
|
|
31
|
+
toMilliseconds({ value: 5, unit: "seconds" }); // => 5000
|
|
45
32
|
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
// Minutes
|
|
34
|
+
toMilliseconds({ value: 1.5, unit: "minutes" }); // => 90000
|
|
48
35
|
|
|
49
|
-
//
|
|
50
|
-
toMilliseconds({ value:
|
|
36
|
+
// Hours
|
|
37
|
+
toMilliseconds({ value: 1, unit: "hours" }); // => 3600000
|
|
51
38
|
|
|
52
|
-
// Days
|
|
53
|
-
toMilliseconds({ value: 1, unit: "days" }); //
|
|
39
|
+
// Days
|
|
40
|
+
toMilliseconds({ value: 1, unit: "days" }); // => 86400000
|
|
54
41
|
|
|
55
|
-
// Fractional
|
|
56
|
-
toMilliseconds({ value: 0.
|
|
42
|
+
// Fractional values
|
|
43
|
+
toMilliseconds({ value: 0.5, unit: "seconds" }); // => 500
|
|
57
44
|
```
|
|
58
45
|
|
|
59
|
-
|
|
60
|
-
|------------|-----------------|
|
|
61
|
-
| milliseconds | 1 |
|
|
62
|
-
| seconds | 1,000 |
|
|
63
|
-
| minutes | 60,000 |
|
|
64
|
-
| hours | 3,600,000 |
|
|
65
|
-
| days | 86,400,000 |
|
|
66
|
-
|
|
67
|
-
### Example: Duration to Milliseconds Table
|
|
68
|
-
|
|
69
|
-
| Duration | Milliseconds |
|
|
70
|
-
|-------------------------|--------------|
|
|
71
|
-
| 1 second | 1,000 |
|
|
72
|
-
| 1.5 minutes | 90,000 |
|
|
73
|
-
| 2 hours | 7,200,000 |
|
|
74
|
-
| 0.5 days | 43,200,000 |
|
|
75
|
-
|
|
76
|
-
## TimeSpan Usage Details
|
|
46
|
+
### TimeSpan Interface
|
|
77
47
|
|
|
78
|
-
|
|
48
|
+
Represents a duration with a numeric value and a unit.
|
|
79
49
|
|
|
80
|
-
|
|
50
|
+
| Property | Type | Description |
|
|
51
|
+
|----------|----------|-------------------------|
|
|
52
|
+
| value | `number` | The numeric duration |
|
|
53
|
+
| unit | `TimeUnit` | The time unit (see below) |
|
|
81
54
|
|
|
82
|
-
|
|
83
|
-
interface TimeSpan {
|
|
84
|
-
value: number;
|
|
85
|
-
unit: TimeUnit;
|
|
86
|
-
}
|
|
55
|
+
### TimeUnit Type
|
|
87
56
|
|
|
88
|
-
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### Additional Examples
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
import { toMilliseconds } from '@hardlydifficult/date-time';
|
|
57
|
+
Supported time units:
|
|
95
58
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Supports all time units (`milliseconds`, `seconds`, `minutes`, `hours`, `days`) and handles fractional values and zero correctly.
|
|
59
|
+
- `"milliseconds"`
|
|
60
|
+
- `"seconds"`
|
|
61
|
+
- `"minutes"`
|
|
62
|
+
- `"hours"`
|
|
63
|
+
- `"days"`
|