@kalyx/core 1.0.0-rc.11 → 1.0.0-rc.12
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/CHANGELOG.md +14 -0
- package/dist/index.cjs +6 -0
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +6 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @kalyx/core
|
|
2
2
|
|
|
3
|
+
## 1.0.0-rc.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0556886: fix(core): validate inputs to `to12Hour` and `to24Hour`
|
|
8
|
+
|
|
9
|
+
`to12Hour(hours24)` and `to24Hour(hours12, period)` are public exports from `@kalyx/core` but had no input validation. The previous silent arithmetic mapped invalid inputs onto plausible-looking but wrong outputs and hid caller bugs:
|
|
10
|
+
- `to12Hour(24)` returned `{ hours12: 12, period: 'PM' }` (because `24 % 12 = 0` → mapped to 12)
|
|
11
|
+
- `to12Hour(-1)` returned `{ hours12: -1, period: 'AM' }`
|
|
12
|
+
- `to24Hour(13, 'PM')` returned `25`
|
|
13
|
+
- `to24Hour(0, 'AM')` returned `0` (but `0` is not a valid 12-hour clock value — midnight is `12 AM`)
|
|
14
|
+
|
|
15
|
+
Both functions now throw `RangeError` with a clear message when the input is outside its valid integer range (`[0, 23]` for `to12Hour`, `[1, 12]` for `to24Hour`). `Number.isInteger` guards non-integers and `NaN`. No `@kalyx/react` callers ever passed invalid values, so the internal contracts are unchanged; only direct `@kalyx/core` users who relied on the silent-wrong behaviour see the new exception.
|
|
16
|
+
|
|
3
17
|
## 1.0.0-rc.11
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/dist/index.cjs
CHANGED
|
@@ -477,12 +477,18 @@ function formatTimeString(time, withSeconds = false) {
|
|
|
477
477
|
return `${hh}:${mm}`;
|
|
478
478
|
}
|
|
479
479
|
function to12Hour(hours24) {
|
|
480
|
+
if (!Number.isInteger(hours24) || hours24 < 0 || hours24 > 23) {
|
|
481
|
+
throw new RangeError(`[to12Hour] hours24 must be an integer in [0, 23], got ${hours24}`);
|
|
482
|
+
}
|
|
480
483
|
const period = hours24 >= 12 ? "PM" : "AM";
|
|
481
484
|
let hours12 = hours24 % 12;
|
|
482
485
|
if (hours12 === 0) hours12 = 12;
|
|
483
486
|
return { hours12, period };
|
|
484
487
|
}
|
|
485
488
|
function to24Hour(hours12, period) {
|
|
489
|
+
if (!Number.isInteger(hours12) || hours12 < 1 || hours12 > 12) {
|
|
490
|
+
throw new RangeError(`[to24Hour] hours12 must be an integer in [1, 12], got ${hours12}`);
|
|
491
|
+
}
|
|
486
492
|
if (period === "AM") {
|
|
487
493
|
return hours12 === 12 ? 0 : hours12;
|
|
488
494
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -218,7 +218,13 @@ declare function parseTimeString(input: string): TimeValue | null;
|
|
|
218
218
|
declare function formatTimeString(time: TimeValue, withSeconds?: boolean): string;
|
|
219
219
|
/**
|
|
220
220
|
* Converts a 24-hour value to 12-hour form.
|
|
221
|
-
*
|
|
221
|
+
*
|
|
222
|
+
* - `0` → `{ hours12: 12, period: 'AM' }` (midnight)
|
|
223
|
+
* - `12` → `{ hours12: 12, period: 'PM' }` (noon)
|
|
224
|
+
*
|
|
225
|
+
* Throws if `hours24` isn't an integer in `[0, 23]`. The previous silent
|
|
226
|
+
* modulo behaviour mapped invalid inputs (e.g. `24`, `25`, `-1`) onto
|
|
227
|
+
* arbitrary valid-looking outputs, which masked caller bugs.
|
|
222
228
|
*/
|
|
223
229
|
declare function to12Hour(hours24: number): {
|
|
224
230
|
hours12: number;
|
|
@@ -226,6 +232,10 @@ declare function to12Hour(hours24: number): {
|
|
|
226
232
|
};
|
|
227
233
|
/**
|
|
228
234
|
* Converts a 12-hour value to 24-hour form.
|
|
235
|
+
*
|
|
236
|
+
* Throws if `hours12` isn't an integer in `[1, 12]`. The previous silent
|
|
237
|
+
* arithmetic produced out-of-range outputs (e.g. `to24Hour(13, 'PM')` → `25`).
|
|
238
|
+
* `period` is constrained at the type level to `'AM' | 'PM'`.
|
|
229
239
|
*/
|
|
230
240
|
declare function to24Hour(hours12: number, period: 'AM' | 'PM'): number;
|
|
231
241
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -218,7 +218,13 @@ declare function parseTimeString(input: string): TimeValue | null;
|
|
|
218
218
|
declare function formatTimeString(time: TimeValue, withSeconds?: boolean): string;
|
|
219
219
|
/**
|
|
220
220
|
* Converts a 24-hour value to 12-hour form.
|
|
221
|
-
*
|
|
221
|
+
*
|
|
222
|
+
* - `0` → `{ hours12: 12, period: 'AM' }` (midnight)
|
|
223
|
+
* - `12` → `{ hours12: 12, period: 'PM' }` (noon)
|
|
224
|
+
*
|
|
225
|
+
* Throws if `hours24` isn't an integer in `[0, 23]`. The previous silent
|
|
226
|
+
* modulo behaviour mapped invalid inputs (e.g. `24`, `25`, `-1`) onto
|
|
227
|
+
* arbitrary valid-looking outputs, which masked caller bugs.
|
|
222
228
|
*/
|
|
223
229
|
declare function to12Hour(hours24: number): {
|
|
224
230
|
hours12: number;
|
|
@@ -226,6 +232,10 @@ declare function to12Hour(hours24: number): {
|
|
|
226
232
|
};
|
|
227
233
|
/**
|
|
228
234
|
* Converts a 12-hour value to 24-hour form.
|
|
235
|
+
*
|
|
236
|
+
* Throws if `hours12` isn't an integer in `[1, 12]`. The previous silent
|
|
237
|
+
* arithmetic produced out-of-range outputs (e.g. `to24Hour(13, 'PM')` → `25`).
|
|
238
|
+
* `period` is constrained at the type level to `'AM' | 'PM'`.
|
|
229
239
|
*/
|
|
230
240
|
declare function to24Hour(hours12: number, period: 'AM' | 'PM'): number;
|
|
231
241
|
/**
|
package/dist/index.js
CHANGED
|
@@ -426,12 +426,18 @@ function formatTimeString(time, withSeconds = false) {
|
|
|
426
426
|
return `${hh}:${mm}`;
|
|
427
427
|
}
|
|
428
428
|
function to12Hour(hours24) {
|
|
429
|
+
if (!Number.isInteger(hours24) || hours24 < 0 || hours24 > 23) {
|
|
430
|
+
throw new RangeError(`[to12Hour] hours24 must be an integer in [0, 23], got ${hours24}`);
|
|
431
|
+
}
|
|
429
432
|
const period = hours24 >= 12 ? "PM" : "AM";
|
|
430
433
|
let hours12 = hours24 % 12;
|
|
431
434
|
if (hours12 === 0) hours12 = 12;
|
|
432
435
|
return { hours12, period };
|
|
433
436
|
}
|
|
434
437
|
function to24Hour(hours12, period) {
|
|
438
|
+
if (!Number.isInteger(hours12) || hours12 < 1 || hours12 > 12) {
|
|
439
|
+
throw new RangeError(`[to24Hour] hours12 must be an integer in [1, 12], got ${hours12}`);
|
|
440
|
+
}
|
|
435
441
|
if (period === "AM") {
|
|
436
442
|
return hours12 === 12 ? 0 : hours12;
|
|
437
443
|
}
|
package/package.json
CHANGED