@autobusal/common 1.24.0 → 1.25.0
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 +8 -0
- package/Calendar/utilities/settings.ts +56 -2
- package/index.ts +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.25.0
|
|
4
|
+
|
|
5
|
+
**New `setDepartureZone(zone)` — the date picker floors on today WHERE THE COACH LEAVES.**
|
|
6
|
+
|
|
7
|
+
`setServerToday` was already an improvement on the buyer's device clock, but it is still the wrong clock: it is *our* date, in Tirana, and a coach leaving Bari has nothing to do with it. Only the departure city can say whether the 4th is still today for that journey.
|
|
8
|
+
|
|
9
|
+
Falls back to `serverToday`, then to the device, so the bare search form (no journey chosen yet) behaves exactly as before. An unresolvable zone returns null and falls back too — a picker that refuses to open because a timezone lookup failed would be far worse than one flooring a day out.
|
|
10
|
+
|
|
3
11
|
## 1.24.0
|
|
4
12
|
|
|
5
13
|
**`Policy` is now `Information`.**
|
|
@@ -13,6 +13,26 @@ import { CalendarLimit, DatesLimit, CalendarData } from '../types';
|
|
|
13
13
|
*/
|
|
14
14
|
let serverToday: Date | null = null;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* The timezone the journey STARTS in, when we know it.
|
|
18
|
+
*
|
|
19
|
+
* Edited: Ferjolt Ozuni - Date: 2026-08-03
|
|
20
|
+
*
|
|
21
|
+
* `serverToday` was already an improvement on the buyer's device clock, but
|
|
22
|
+
* it is still the wrong clock - it is OUR date, in Tirana, and a coach
|
|
23
|
+
* leaving Bari has nothing to do with it. Only the departure city can say
|
|
24
|
+
* whether the 4th is still today for that journey.
|
|
25
|
+
*
|
|
26
|
+
* Null until a departure city is chosen, which is why serverToday remains
|
|
27
|
+
* the fallback rather than being replaced: on the bare search form there is
|
|
28
|
+
* no journey yet to take a clock from.
|
|
29
|
+
*/
|
|
30
|
+
let departureZone: string | null = null;
|
|
31
|
+
|
|
32
|
+
export const setDepartureZone = (zone?: string | null): void => {
|
|
33
|
+
departureZone = zone ?? null;
|
|
34
|
+
};
|
|
35
|
+
|
|
16
36
|
export const setServerToday = (value?: string): void => {
|
|
17
37
|
if (!value) {
|
|
18
38
|
return;
|
|
@@ -40,8 +60,8 @@ export const getLimits = (type: ('picker' | 'dob' | 'date')): CalendarLimit => {
|
|
|
40
60
|
//
|
|
41
61
|
// A date of birth genuinely is about the person in front of the screen,
|
|
42
62
|
// so that one keeps the local clock.
|
|
43
|
-
const today =
|
|
44
|
-
? new Date(serverToday.getTime())
|
|
63
|
+
const today = type === 'picker'
|
|
64
|
+
? (departureToday() ?? (serverToday ? new Date(serverToday.getTime()) : new Date()))
|
|
45
65
|
: new Date();
|
|
46
66
|
|
|
47
67
|
today.setHours(0, 0, 0, 0);
|
|
@@ -91,6 +111,40 @@ export const getLimits = (type: ('picker' | 'dob' | 'date')): CalendarLimit => {
|
|
|
91
111
|
};
|
|
92
112
|
};
|
|
93
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Today, as the departure city reckons it.
|
|
116
|
+
*
|
|
117
|
+
* Edited: Ferjolt Ozuni - Date: 2026-08-03
|
|
118
|
+
*
|
|
119
|
+
* en-CA because it formats as YYYY-MM-DD, which parses unambiguously - the
|
|
120
|
+
* one thing a date string in this codebase has repeatedly failed to do.
|
|
121
|
+
* Built from the PARTS rather than parsed from the string, so the result is
|
|
122
|
+
* a local midnight on that calendar day rather than a UTC instant that can
|
|
123
|
+
* land on the day before.
|
|
124
|
+
*
|
|
125
|
+
* Returns null when there is no zone or the runtime rejects it, and every
|
|
126
|
+
* caller falls back - a picker that refuses to open because a timezone
|
|
127
|
+
* lookup failed would be far worse than one flooring on the wrong day.
|
|
128
|
+
*/
|
|
129
|
+
const departureToday = (): Date | null => {
|
|
130
|
+
if (!departureZone) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
const [ year, month, day ] = new Intl.DateTimeFormat('en-CA', {
|
|
136
|
+
timeZone: departureZone,
|
|
137
|
+
year: 'numeric',
|
|
138
|
+
month: '2-digit',
|
|
139
|
+
day: '2-digit'
|
|
140
|
+
}).format(new Date()).split('-').map(Number);
|
|
141
|
+
|
|
142
|
+
return new Date(year, month - 1, day, 0, 0, 0, 0);
|
|
143
|
+
} catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
94
148
|
export const getCalendar = (value: string): CalendarData => {
|
|
95
149
|
const prepared = createDate(value);
|
|
96
150
|
|
package/index.ts
CHANGED
|
@@ -26,7 +26,7 @@ import Paragraph from './Loading/Paragraph';
|
|
|
26
26
|
import Passengers from './Passengers/Passengers';
|
|
27
27
|
import Password from './Password/Password';
|
|
28
28
|
import Rating from './Rating/Rating';
|
|
29
|
-
import { setServerToday } from './Calendar/utilities/settings';
|
|
29
|
+
import { setServerToday, setDepartureZone } from './Calendar/utilities/settings';
|
|
30
30
|
import Information from './Information/Information';
|
|
31
31
|
import Report from './Report/Report';
|
|
32
32
|
import RouteFeature from './RouteFeature/RouteFeature';
|
|
@@ -77,6 +77,7 @@ export {
|
|
|
77
77
|
Password,
|
|
78
78
|
Rating,
|
|
79
79
|
setServerToday,
|
|
80
|
+
setDepartureZone,
|
|
80
81
|
Information,
|
|
81
82
|
Report,
|
|
82
83
|
RouteFeature,
|