@hardlydifficult/date-time 1.0.6 → 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.
Files changed (2) hide show
  1. package/README.md +29 -66
  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 representing time durations and converting them to milliseconds.
4
4
 
5
5
  ## Installation
6
6
 
@@ -14,87 +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
- console.log(toMilliseconds(duration)); // 150000
17
+ const milliseconds = toMilliseconds(duration);
18
+ // => 150000
18
19
  ```
19
20
 
20
- ## Duration Conversion
21
+ ## Time Duration Conversion
21
22
 
22
- The package provides a strongly-typed `TimeSpan` interface and a utility function `toMilliseconds` for converting time durations to milliseconds.
23
-
24
- ### TimeSpan Interface
25
-
26
- Represents a time duration with a numeric value and a unit.
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:
36
-
37
- - `"milliseconds"`
38
- - `"seconds"`
39
- - `"minutes"`
40
- - `"hours"`
41
- - `"days"`
42
-
43
- ### toMilliseconds Function
23
+ ### toMilliseconds
44
24
 
45
25
  Converts a `TimeSpan` to its equivalent value in milliseconds.
46
26
 
47
27
  ```typescript
48
28
  import { toMilliseconds, type TimeSpan } from "@hardlydifficult/date-time";
49
29
 
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
- ];
56
-
57
- durations.forEach(duration => {
58
- console.log(toMilliseconds(duration)); // 1000, 1800000, 172800000
59
- });
60
- ```
30
+ // Seconds
31
+ toMilliseconds({ value: 5, unit: "seconds" }); // => 5000
61
32
 
62
- ### Example: Duration to Milliseconds Table
33
+ // Minutes
34
+ toMilliseconds({ value: 1.5, unit: "minutes" }); // => 90000
63
35
 
64
- | Duration | Milliseconds |
65
- |-------------------------|--------------|
66
- | 1 second | 1,000 |
67
- | 1.5 minutes | 90,000 |
68
- | 2 hours | 7,200,000 |
69
- | 0.5 days | 43,200,000 |
36
+ // Hours
37
+ toMilliseconds({ value: 1, unit: "hours" }); // => 3600000
70
38
 
71
- ## TimeSpan
39
+ // Days
40
+ toMilliseconds({ value: 1, unit: "days" }); // => 86400000
72
41
 
73
- A strongly-typed duration representation that pairs a numeric value with a time unit, enabling human-readable time specifications that convert to milliseconds.
74
-
75
- ### Type Definition
76
-
77
- ```typescript
78
- interface TimeSpan {
79
- value: number;
80
- unit: TimeUnit;
81
- }
82
-
83
- type TimeUnit = 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days';
42
+ // Fractional values
43
+ toMilliseconds({ value: 0.5, unit: "seconds" }); // => 500
84
44
  ```
85
45
 
86
- ### toMilliseconds()
46
+ ### TimeSpan Interface
87
47
 
88
- Converts a `TimeSpan` to its equivalent value in milliseconds.
48
+ Represents a duration with a numeric value and a unit.
89
49
 
90
- ```typescript
91
- import { toMilliseconds } from '@hardlydifficult/date-time';
50
+ | Property | Type | Description |
51
+ |----------|----------|-------------------------|
52
+ | value | `number` | The numeric duration |
53
+ | unit | `TimeUnit` | The time unit (see below) |
92
54
 
93
- toMilliseconds({ value: 2, unit: 'seconds' }); // 2000
94
- toMilliseconds({ value: 1, unit: 'hours' }); // 3600000
95
- toMilliseconds({ value: 0.5, unit: 'seconds' }); // 500
96
- toMilliseconds({ value: 0, unit: 'minutes' }); // 0
97
- toMilliseconds({ value: 1, unit: 'days' }); // 86400000
98
- ```
55
+ ### TimeUnit Type
56
+
57
+ Supported time units:
99
58
 
100
- 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"`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardlydifficult/date-time",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [