@hardlydifficult/date-time 1.0.7 → 1.0.9

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.
Files changed (2) hide show
  1. package/README.md +21 -67
  2. 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 human-readable duration types and millisecond conversion utilities.
3
+ A TypeScript utility for converting time durations to milliseconds with strong typing.
4
4
 
5
5
  ## Installation
6
6
 
@@ -14,90 +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
- console.log(toMilliseconds(duration)); // 150_000
17
+ const ms = toMilliseconds(duration); // 150_000
18
18
  ```
19
19
 
20
- ## Time Spans and Conversion
20
+ ## TimeSpan Conversion
21
21
 
22
- Convert time durations to milliseconds using a strongly-typed `TimeSpan` interface.
22
+ Converts a time duration to its equivalent in milliseconds using predefined unit multipliers.
23
23
 
24
- ### TimeSpan Interface
24
+ ### `TimeSpan` Interface
25
25
 
26
26
  Represents a time duration with a numeric `value` and a `unit`.
27
27
 
28
- ```typescript
29
- interface TimeSpan {
30
- value: number;
31
- unit: TimeUnit;
32
- }
33
- ```
28
+ | Field | Type | Description |
29
+ |-------|----------|----------------------|
30
+ | value | `number` | The numeric duration |
31
+ | unit | `TimeUnit` | The time unit |
32
+
33
+ ### `TimeUnit` Type
34
34
 
35
- Where `TimeUnit` supports:
35
+ Supported time units:
36
36
  - `"milliseconds"`
37
37
  - `"seconds"`
38
38
  - `"minutes"`
39
39
  - `"hours"`
40
40
  - `"days"`
41
41
 
42
- ### toMilliseconds()
42
+ ### `toMilliseconds(timeSpan)`
43
43
 
44
- Converts a `TimeSpan` to its equivalent in milliseconds.
44
+ Converts a `TimeSpan` to milliseconds.
45
45
 
46
46
  ```typescript
47
47
  import { toMilliseconds } from "@hardlydifficult/date-time";
48
48
 
49
- // Minutes to milliseconds
50
- toMilliseconds({ value: 5, unit: "minutes" }); // 300_000
51
-
52
- // Days to milliseconds
53
- toMilliseconds({ value: 1, unit: "days" }); // 86_400_000
54
-
55
- // Fractional hours
56
- toMilliseconds({ value: 0.75, unit: "hours" }); // 2_700_000
57
- ```
58
-
59
- | Unit | Multiplier (ms) |
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
49
+ // Convert 2 hours
50
+ toMilliseconds({ value: 2, unit: "hours" }); // 7_200_000
77
51
 
78
- A strongly-typed duration representation that pairs a numeric value with a time unit, enabling human-readable time specifications that convert to milliseconds.
79
-
80
- ### Type Definition
81
-
82
- ```typescript
83
- interface TimeSpan {
84
- value: number;
85
- unit: TimeUnit;
86
- }
87
-
88
- type TimeUnit = 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days';
89
- ```
90
-
91
- ### Additional Examples
92
-
93
- ```typescript
94
- import { toMilliseconds } from '@hardlydifficult/date-time';
95
-
96
- toMilliseconds({ value: 2, unit: 'seconds' }); // 2000
97
- toMilliseconds({ value: 1, unit: 'hours' }); // 3600000
98
- toMilliseconds({ value: 0.5, unit: 'seconds' }); // 500
99
- toMilliseconds({ value: 0, unit: 'minutes' }); // 0
100
- toMilliseconds({ value: 1, unit: 'days' }); // 86400000
101
- ```
52
+ // Convert 0.5 days
53
+ toMilliseconds({ value: 0.5, unit: "days" }); // 43_200_000
102
54
 
103
- Supports all time units (`milliseconds`, `seconds`, `minutes`, `hours`, `days`) and handles fractional values and zero correctly.
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.7",
3
+ "version": "1.0.9",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [