@hardlydifficult/date-time 1.0.2 → 1.0.3
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 +31 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @hardlydifficult/date-time
|
|
2
2
|
|
|
3
|
-
Date and time utilities.
|
|
3
|
+
Date and time utilities for TypeScript, providing human-readable duration types with millisecond conversion.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,17 +8,41 @@ Date and time utilities.
|
|
|
8
8
|
npm install @hardlydifficult/date-time
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
Human-readable duration type with millisecond conversion.
|
|
11
|
+
## Quick Start
|
|
14
12
|
|
|
15
13
|
```typescript
|
|
16
14
|
import { toMilliseconds, type TimeSpan } from '@hardlydifficult/date-time';
|
|
17
15
|
|
|
18
16
|
const delay: TimeSpan = { value: 1.5, unit: 'minutes' };
|
|
19
|
-
toMilliseconds(delay); // 90000
|
|
17
|
+
console.log(toMilliseconds(delay)); // 90000
|
|
20
18
|
```
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
## TimeSpan
|
|
21
|
+
|
|
22
|
+
A strongly-typed duration representation that pairs a numeric value with a time unit, enabling human-readable time specifications that convert to milliseconds.
|
|
23
|
+
|
|
24
|
+
### Type Definition
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
interface TimeSpan {
|
|
28
|
+
value: number;
|
|
29
|
+
unit: TimeUnit;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type TimeUnit = 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days';
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### toMilliseconds()
|
|
36
|
+
|
|
37
|
+
Converts a `TimeSpan` to its equivalent value in milliseconds.
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { toMilliseconds } from '@hardlydifficult/date-time';
|
|
41
|
+
|
|
42
|
+
toMilliseconds({ value: 2, unit: 'seconds' }); // 2000
|
|
43
|
+
toMilliseconds({ value: 1, unit: 'hours' }); // 3600000
|
|
44
|
+
toMilliseconds({ value: 0.5, unit: 'seconds' }); // 500 (fractional values supported)
|
|
45
|
+
toMilliseconds({ value: 0, unit: 'minutes' }); // 0
|
|
46
|
+
```
|
|
23
47
|
|
|
24
|
-
|
|
48
|
+
Supports all time units and handles fractional values correctly.
|