@autobusal/utilities 1.5.4 → 1.5.5
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 +4 -0
- package/date.tsx +37 -0
- package/index.ts +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.5.5 (2026-08-29)
|
|
4
|
+
|
|
5
|
+
- New isPreparedDate(): whether a string is a d/m/Y date the app can work with - createDate turns anything else into an Invalid Date, which is how the search URL's literal 'none' produced a January calendar.
|
|
6
|
+
|
|
3
7
|
## 1.5.4 (2026-08-28)
|
|
4
8
|
|
|
5
9
|
- DisplayStatus renders status 4 (awaiting approval) as a badge instead of a blank cell in the admin agent/visitor/API-consumer lists (sweep #61).
|
package/date.tsx
CHANGED
|
@@ -6,6 +6,43 @@ export const createDate = (prepared: string): Date => {
|
|
|
6
6
|
return new Date(Date.UTC(Number(data[2]), Number(data[1]) - 1, Number(data[0])));
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Whether a string is a d/m/Y date this app can actually work with.
|
|
11
|
+
*
|
|
12
|
+
* Claude - Date: 2026-08-29
|
|
13
|
+
*
|
|
14
|
+
* `createDate` splits on "/" and feeds the pieces to Date.UTC, so anything
|
|
15
|
+
* that is not a date at all produces an Invalid Date rather than an error -
|
|
16
|
+
* and a calendar built from one renders January of nothing. The literal
|
|
17
|
+
* "none" the search URL carries for "no return leg" is exactly that, which
|
|
18
|
+
* is how the round-trip picker came to open on January instead of the
|
|
19
|
+
* outbound's month.
|
|
20
|
+
*/
|
|
21
|
+
export const isPreparedDate = (value?: string | null): boolean => {
|
|
22
|
+
if (!value) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const parts = value.split('/');
|
|
27
|
+
|
|
28
|
+
if (parts.length !== 3) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const [ day, month, year ] = parts.map(Number);
|
|
33
|
+
|
|
34
|
+
if (!day || !month || !year) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
39
|
+
|
|
40
|
+
// round-trips through Date so 31/02/2026 is refused as well as "none"
|
|
41
|
+
return date.getUTCFullYear() === year
|
|
42
|
+
&& date.getUTCMonth() === month - 1
|
|
43
|
+
&& date.getUTCDate() === day;
|
|
44
|
+
};
|
|
45
|
+
|
|
9
46
|
export const prepareDate = (date: Date): string => {
|
|
10
47
|
const day = date.getDate();
|
|
11
48
|
const month = date.getMonth() + 1;
|
package/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createDate, prepareDate, getFormattedShort, getDayParts, differenceYears, futureDate } from './date';
|
|
1
|
+
import { createDate, prepareDate, isPreparedDate, getFormattedShort, getDayParts, differenceYears, futureDate } from './date';
|
|
2
2
|
import { Validate, Display } from './form';
|
|
3
3
|
import { error, notify, success } from './notify';
|
|
4
4
|
import { getAllowed, getLanguages, getPayments } from './options';
|
|
@@ -17,6 +17,7 @@ export {
|
|
|
17
17
|
success,
|
|
18
18
|
createDate,
|
|
19
19
|
prepareDate,
|
|
20
|
+
isPreparedDate,
|
|
20
21
|
getFormattedShort,
|
|
21
22
|
getDayParts,
|
|
22
23
|
differenceYears,
|