@hardlydifficult/date-time 1.0.5 → 1.0.7

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 +32 -29
  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 providing human-readable duration types and millisecond conversion utilities.
3
+ A TypeScript library for human-readable duration types and millisecond conversion utilities.
4
4
 
5
5
  ## Installation
6
6
 
@@ -14,51 +14,56 @@ 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)); // 150000
17
+ console.log(toMilliseconds(duration)); // 150_000
18
18
  ```
19
19
 
20
- ## Duration Conversion
20
+ ## Time Spans and Conversion
21
21
 
22
- The package provides a strongly-typed `TimeSpan` interface and a utility function `toMilliseconds` for converting time durations to milliseconds.
22
+ Convert time durations to milliseconds using a strongly-typed `TimeSpan` interface.
23
23
 
24
24
  ### TimeSpan Interface
25
25
 
26
- Represents a time duration with a numeric value and a unit.
26
+ Represents a time duration with a numeric `value` and a `unit`.
27
27
 
28
- | Property | Type | Description |
29
- |----------|----------|-------------------------|
30
- | value | `number` | The numeric value |
31
- | unit | `TimeUnit` | The time unit of the value |
32
-
33
- ### TimeUnit Type
34
-
35
- Supported time units:
28
+ ```typescript
29
+ interface TimeSpan {
30
+ value: number;
31
+ unit: TimeUnit;
32
+ }
33
+ ```
36
34
 
35
+ Where `TimeUnit` supports:
37
36
  - `"milliseconds"`
38
37
  - `"seconds"`
39
38
  - `"minutes"`
40
39
  - `"hours"`
41
40
  - `"days"`
42
41
 
43
- ### toMilliseconds Function
42
+ ### toMilliseconds()
44
43
 
45
- Converts a `TimeSpan` to its equivalent value in milliseconds.
44
+ Converts a `TimeSpan` to its equivalent in milliseconds.
46
45
 
47
46
  ```typescript
48
- import { toMilliseconds, type TimeSpan } from "@hardlydifficult/date-time";
47
+ import { toMilliseconds } from "@hardlydifficult/date-time";
48
+
49
+ // Minutes to milliseconds
50
+ toMilliseconds({ value: 5, unit: "minutes" }); // 300_000
49
51
 
50
- // Convert various durations
51
- const durations: TimeSpan[] = [
52
- { value: 1, unit: "seconds" },
53
- { value: 0.5, unit: "hours" },
54
- { value: 2, unit: "days" }
55
- ];
52
+ // Days to milliseconds
53
+ toMilliseconds({ value: 1, unit: "days" }); // 86_400_000
56
54
 
57
- durations.forEach(duration => {
58
- console.log(toMilliseconds(duration)); // 1000, 1800000, 172800000
59
- });
55
+ // Fractional hours
56
+ toMilliseconds({ value: 0.75, unit: "hours" }); // 2_700_000
60
57
  ```
61
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
+
62
67
  ### Example: Duration to Milliseconds Table
63
68
 
64
69
  | Duration | Milliseconds |
@@ -68,7 +73,7 @@ durations.forEach(duration => {
68
73
  | 2 hours | 7,200,000 |
69
74
  | 0.5 days | 43,200,000 |
70
75
 
71
- ## TimeSpan
76
+ ## TimeSpan Usage Details
72
77
 
73
78
  A strongly-typed duration representation that pairs a numeric value with a time unit, enabling human-readable time specifications that convert to milliseconds.
74
79
 
@@ -83,9 +88,7 @@ interface TimeSpan {
83
88
  type TimeUnit = 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days';
84
89
  ```
85
90
 
86
- ### toMilliseconds()
87
-
88
- Converts a `TimeSpan` to its equivalent value in milliseconds.
91
+ ### Additional Examples
89
92
 
90
93
  ```typescript
91
94
  import { toMilliseconds } from '@hardlydifficult/date-time';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardlydifficult/date-time",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [