@hardlydifficult/date-time 1.0.10 → 1.0.11
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 +29 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,45 +13,54 @@ npm install @hardlydifficult/date-time
|
|
|
13
13
|
```typescript
|
|
14
14
|
import { toMilliseconds, type TimeSpan } from "@hardlydifficult/date-time";
|
|
15
15
|
|
|
16
|
-
const duration: TimeSpan = { value: 2
|
|
17
|
-
const
|
|
16
|
+
const duration: TimeSpan = { value: 2, unit: "minutes" };
|
|
17
|
+
const milliseconds = toMilliseconds(duration); // 120_000
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## TimeSpan Conversion
|
|
21
21
|
|
|
22
|
-
Converts a time duration to its equivalent in milliseconds
|
|
22
|
+
Converts a time duration (represented as a `TimeSpan`) to its equivalent value in milliseconds.
|
|
23
23
|
|
|
24
|
-
###
|
|
24
|
+
### Interface
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
| Property | Type | Description |
|
|
27
|
+
|----------|----------|----------------------------|
|
|
28
|
+
| `value` | `number` | The numeric value of time |
|
|
29
|
+
| `unit` | `TimeUnit` | The time unit (see below) |
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|-------|----------|----------------------|
|
|
30
|
-
| value | `number` | The numeric duration |
|
|
31
|
-
| unit | `TimeUnit` | The time unit |
|
|
31
|
+
### TimeUnit Options
|
|
32
32
|
|
|
33
|
-
### `TimeUnit` Type
|
|
34
|
-
|
|
35
|
-
Supported time units:
|
|
36
33
|
- `"milliseconds"`
|
|
37
34
|
- `"seconds"`
|
|
38
35
|
- `"minutes"`
|
|
39
36
|
- `"hours"`
|
|
40
37
|
- `"days"`
|
|
41
38
|
|
|
42
|
-
###
|
|
39
|
+
### Function
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
toMilliseconds(timeSpan: TimeSpan): number
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Converts the given time span to milliseconds using predefined unit multipliers.
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
### Examples
|
|
45
48
|
|
|
46
49
|
```typescript
|
|
47
50
|
import { toMilliseconds } from "@hardlydifficult/date-time";
|
|
48
51
|
|
|
49
|
-
//
|
|
50
|
-
toMilliseconds({ value: 2, unit: "
|
|
52
|
+
// Seconds to milliseconds
|
|
53
|
+
toMilliseconds({ value: 2, unit: "seconds" }); // 2_000
|
|
51
54
|
|
|
52
|
-
//
|
|
53
|
-
toMilliseconds({ value: 0.5, unit: "days" }); // 43_200_000
|
|
54
|
-
|
|
55
|
-
// Handle fractional values
|
|
55
|
+
// Minutes to milliseconds
|
|
56
56
|
toMilliseconds({ value: 1.5, unit: "minutes" }); // 90_000
|
|
57
|
+
|
|
58
|
+
// Days to milliseconds
|
|
59
|
+
toMilliseconds({ value: 1, unit: "days" }); // 86_400_000
|
|
60
|
+
|
|
61
|
+
// Fractional value
|
|
62
|
+
toMilliseconds({ value: 0.5, unit: "seconds" }); // 500
|
|
63
|
+
|
|
64
|
+
// Zero duration
|
|
65
|
+
toMilliseconds({ value: 0, unit: "hours" }); // 0
|
|
57
66
|
```
|