@hardlydifficult/date-time 1.0.7 → 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 +30 -70
  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 library for representing time durations and converting them to milliseconds.
4
4
 
5
5
  ## Installation
6
6
 
@@ -14,90 +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)); // 150_000
17
+ const milliseconds = toMilliseconds(duration);
18
+ // => 150000
18
19
  ```
19
20
 
20
- ## Time Spans and Conversion
21
+ ## Time Duration Conversion
21
22
 
22
- Convert time durations to milliseconds using a strongly-typed `TimeSpan` interface.
23
+ ### toMilliseconds
23
24
 
24
- ### TimeSpan Interface
25
-
26
- Represents a time duration with a numeric `value` and a `unit`.
25
+ Converts a `TimeSpan` to its equivalent value in milliseconds.
27
26
 
28
27
  ```typescript
29
- interface TimeSpan {
30
- value: number;
31
- unit: TimeUnit;
32
- }
33
- ```
34
-
35
- Where `TimeUnit` supports:
36
- - `"milliseconds"`
37
- - `"seconds"`
38
- - `"minutes"`
39
- - `"hours"`
40
- - `"days"`
41
-
42
- ### toMilliseconds()
28
+ import { toMilliseconds, type TimeSpan } from "@hardlydifficult/date-time";
43
29
 
44
- Converts a `TimeSpan` to its equivalent in milliseconds.
30
+ // Seconds
31
+ toMilliseconds({ value: 5, unit: "seconds" }); // => 5000
45
32
 
46
- ```typescript
47
- import { toMilliseconds } from "@hardlydifficult/date-time";
33
+ // Minutes
34
+ toMilliseconds({ value: 1.5, unit: "minutes" }); // => 90000
48
35
 
49
- // Minutes to milliseconds
50
- toMilliseconds({ value: 5, unit: "minutes" }); // 300_000
36
+ // Hours
37
+ toMilliseconds({ value: 1, unit: "hours" }); // => 3600000
51
38
 
52
- // Days to milliseconds
53
- toMilliseconds({ value: 1, unit: "days" }); // 86_400_000
39
+ // Days
40
+ toMilliseconds({ value: 1, unit: "days" }); // => 86400000
54
41
 
55
- // Fractional hours
56
- toMilliseconds({ value: 0.75, unit: "hours" }); // 2_700_000
42
+ // Fractional values
43
+ toMilliseconds({ value: 0.5, unit: "seconds" }); // => 500
57
44
  ```
58
45
 
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
46
+ ### TimeSpan Interface
77
47
 
78
- A strongly-typed duration representation that pairs a numeric value with a time unit, enabling human-readable time specifications that convert to milliseconds.
48
+ Represents a duration with a numeric value and a unit.
79
49
 
80
- ### Type Definition
50
+ | Property | Type | Description |
51
+ |----------|----------|-------------------------|
52
+ | value | `number` | The numeric duration |
53
+ | unit | `TimeUnit` | The time unit (see below) |
81
54
 
82
- ```typescript
83
- interface TimeSpan {
84
- value: number;
85
- unit: TimeUnit;
86
- }
55
+ ### TimeUnit Type
87
56
 
88
- type TimeUnit = 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days';
89
- ```
90
-
91
- ### Additional Examples
92
-
93
- ```typescript
94
- import { toMilliseconds } from '@hardlydifficult/date-time';
57
+ Supported time units:
95
58
 
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
- ```
102
-
103
- 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.7",
3
+ "version": "1.0.8",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [