mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-09 08:18:20 +00:00
Merge pull request #822 from Tria-plc/quick-fix-main
Search schedule update
This commit is contained in:
@@ -18,12 +18,11 @@
|
|||||||
* parseEthiopianTime('2026-06-15') // Treats as midnight EAT
|
* parseEthiopianTime('2026-06-15') // Treats as midnight EAT
|
||||||
*/
|
*/
|
||||||
export function parseEthiopianTime(dateInput: string | Date): Date {
|
export function parseEthiopianTime(dateInput: string | Date): Date {
|
||||||
if (dateInput instanceof Date) {
|
if (dateInput instanceof Date) return dateInput;
|
||||||
return dateInput;
|
// Already has timezone info (Z or +HH:MM) — parse directly as UTC
|
||||||
}
|
if (/Z$|[+-]\d{2}:\d{2}$/.test(dateInput)) return new Date(dateInput);
|
||||||
|
// Bare local string (e.g. "2026-07-23T21:00") — treat explicitly as EAT (UTC+3)
|
||||||
// Parse as local time (EAT) since TZ is set to Africa/Addis_Ababa
|
return new Date(dateInput + '+03:00');
|
||||||
return new Date(dateInput);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -153,8 +153,8 @@ export class SearchService {
|
|||||||
nationality?: string,
|
nationality?: string,
|
||||||
) {
|
) {
|
||||||
const [y, m, d] = dateStr.split('-').map(Number);
|
const [y, m, d] = dateStr.split('-').map(Number);
|
||||||
const requestedDate = new Date(y, m - 1, d, 0, 0, 0, 0);
|
const requestedDate = new Date(`${String(y)}-${String(m).padStart(2,'0')}-${String(d).padStart(2,'0')}T00:00:00+03:00`);
|
||||||
const requestedNextDay = new Date(y, m - 1, d + 1, 0, 0, 0, 0);
|
const requestedNextDay = new Date(`${String(y)}-${String(m).padStart(2,'0')}-${String(d + 1).padStart(2,'0')}T00:00:00+03:00`);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const totalPassengers = adultCount + (childCount ?? 0);
|
const totalPassengers = adultCount + (childCount ?? 0);
|
||||||
const NEEDED = 3;
|
const NEEDED = 3;
|
||||||
@@ -213,14 +213,15 @@ export class SearchService {
|
|||||||
nationality?: string,
|
nationality?: string,
|
||||||
) {
|
) {
|
||||||
const [y, m, d] = dateStr.split('-').map(Number);
|
const [y, m, d] = dateStr.split('-').map(Number);
|
||||||
const date = new Date(y, m - 1, d, 0, 0, 0, 0);
|
const date = new Date(`${String(y)}-${String(m).padStart(2,'0')}-${String(d).padStart(2,'0')}T00:00:00+03:00`);
|
||||||
const nextDay = new Date(y, m - 1, d + 1, 0, 0, 0, 0);
|
const nextDay = new Date(`${String(y)}-${String(m).padStart(2,'0')}-${String(d + 1).padStart(2,'0')}T00:00:00+03:00`);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const totalPassengers = adultCount + (childCount ?? 0);
|
const totalPassengers = adultCount + (childCount ?? 0);
|
||||||
|
|
||||||
const cutoffHours = await this.getCutoffHours();
|
const cutoffHours = await this.getCutoffHours();
|
||||||
const cutoffThreshold = new Date(now.getTime() + cutoffHours * 60 * 60 * 1000);
|
const cutoffThreshold = new Date(now.getTime() + cutoffHours * 60 * 60 * 1000);
|
||||||
const isToday = now.getFullYear() === y && now.getMonth() === m - 1 && now.getDate() === d;
|
const nowInEAT = new Date(now.toLocaleString('en-US', { timeZone: 'Africa/Addis_Ababa' }));
|
||||||
|
const isToday = nowInEAT.getFullYear() === y && nowInEAT.getMonth() === m - 1 && nowInEAT.getDate() === d;
|
||||||
const earliest = isToday ? cutoffThreshold : date;
|
const earliest = isToday ? cutoffThreshold : date;
|
||||||
|
|
||||||
const schedules = await this.prisma.trainSchedule.findMany({
|
const schedules = await this.prisma.trainSchedule.findMany({
|
||||||
@@ -255,8 +256,8 @@ export class SearchService {
|
|||||||
nationality?: string,
|
nationality?: string,
|
||||||
) {
|
) {
|
||||||
const [y, m, d] = dateStr.split('-').map(Number);
|
const [y, m, d] = dateStr.split('-').map(Number);
|
||||||
const dayStart = new Date(y, m - 1, d, 0, 0, 0, 0);
|
const dayStart = new Date(`${String(y)}-${String(m).padStart(2,'0')}-${String(d).padStart(2,'0')}T00:00:00+03:00`);
|
||||||
const dayEnd = new Date(y, m - 1, d + 1, 0, 0, 0, 0);
|
const dayEnd = new Date(`${String(y)}-${String(m).padStart(2,'0')}-${String(d + 1).padStart(2,'0')}T00:00:00+03:00`);
|
||||||
const leg2WindowEnd = new Date(dayEnd.getTime() + this.MAX_CONNECTION_MINUTES * 60_000);
|
const leg2WindowEnd = new Date(dayEnd.getTime() + this.MAX_CONNECTION_MINUTES * 60_000);
|
||||||
const totalPassengers = adultCount + (childCount ?? 0);
|
const totalPassengers = adultCount + (childCount ?? 0);
|
||||||
|
|
||||||
@@ -442,8 +443,8 @@ export class SearchService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const coachTypes = this.buildCoachTypeDetails(schedule, faresByClass, nationality, availabilityByClass);
|
const coachTypes = this.buildCoachTypeDetails(schedule, faresByClass, nationality, availabilityByClass);
|
||||||
const legDepartureAt = originStop.plannedDepartureAt ?? schedule.departureAt;
|
const legDepartureAt = schedule.departureAt;
|
||||||
const legArrivalAt = destStop.plannedArrivalAt ?? schedule.arrivalAt;
|
const legArrivalAt = schedule.arrivalAt;
|
||||||
|
|
||||||
const displayCurrency = faresByClass[0]?.displayCurrency ?? resolveCurrencyFromNationality(nationality);
|
const displayCurrency = faresByClass[0]?.displayCurrency ?? resolveCurrencyFromNationality(nationality);
|
||||||
|
|
||||||
|
|||||||
@@ -300,7 +300,7 @@ export default function SchedulesPage() {
|
|||||||
const payload: any = {
|
const payload: any = {
|
||||||
trainId: bulkForm.trainId,
|
trainId: bulkForm.trainId,
|
||||||
routeId: bulkForm.routeId,
|
routeId: bulkForm.routeId,
|
||||||
startDateTime: bulkForm.startDateTime,
|
startDateTime: new Date(bulkForm.startDateTime).toISOString(),
|
||||||
durationHours: parseInt(bulkForm.durationHours),
|
durationHours: parseInt(bulkForm.durationHours),
|
||||||
repeatEveryDays: parseInt(bulkForm.repeatEveryDays),
|
repeatEveryDays: parseInt(bulkForm.repeatEveryDays),
|
||||||
forNextDays: parseInt(bulkForm.forNextDays),
|
forNextDays: parseInt(bulkForm.forNextDays),
|
||||||
@@ -389,11 +389,11 @@ export default function SchedulesPage() {
|
|||||||
const handleEditClick = (schedule: Schedule) => {
|
const handleEditClick = (schedule: Schedule) => {
|
||||||
setEditingSchedule(schedule);
|
setEditingSchedule(schedule);
|
||||||
|
|
||||||
// Format UTC ISO string as local YYYY-MM-DDTHH:mm for the picker
|
// Format UTC ISO string as EAT (Africa/Addis_Ababa) YYYY-MM-DDTHH:mm for the picker
|
||||||
const toLocalDT = (iso: string) => {
|
const toLocalDT = (iso: string) => {
|
||||||
const d = new Date(iso);
|
const eat = new Date(new Date(iso).toLocaleString('en-US', { timeZone: 'Africa/Addis_Ababa' }));
|
||||||
const pad = (n: number) => String(n).padStart(2, '0');
|
const pad = (n: number) => String(n).padStart(2, '0');
|
||||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
return `${eat.getFullYear()}-${pad(eat.getMonth() + 1)}-${pad(eat.getDate())}T${pad(eat.getHours())}:${pad(eat.getMinutes())}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const depStr = toLocalDT(schedule.departureAt);
|
const depStr = toLocalDT(schedule.departureAt);
|
||||||
|
|||||||
Reference in New Issue
Block a user