feature: a mocked implementation of v1 UI done.
This commit is contained in:
25
frontend/src/lib/treatmentSelection.ts
Normal file
25
frontend/src/lib/treatmentSelection.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { isSameLocalCalendarDay } from '@/lib/appointmentTime';
|
||||
import type { TreatmentAppointment } from '@/types/treatment';
|
||||
|
||||
/**
|
||||
* For the selected calendar day: if it is today, pick the appointment whose time range contains now;
|
||||
* otherwise pick the first appointment of that day. Returns null when there are no appointments.
|
||||
*/
|
||||
export function pickAutoAppointment(
|
||||
appointments: TreatmentAppointment[],
|
||||
selectedDay: Date,
|
||||
): string | null {
|
||||
if (appointments.length === 0) return null;
|
||||
|
||||
const now = new Date();
|
||||
if (isSameLocalCalendarDay(selectedDay, now)) {
|
||||
const t = now.getTime();
|
||||
for (const a of appointments) {
|
||||
const s = new Date(a.startAt).getTime();
|
||||
const e = new Date(a.endAt).getTime();
|
||||
if (t >= s && t <= e) return a.id;
|
||||
}
|
||||
}
|
||||
|
||||
return appointments[0].id;
|
||||
}
|
||||
Reference in New Issue
Block a user