timetable maybe working, very cloase at least
This commit is contained in:
@@ -32,9 +32,7 @@ export function localToUTC(localValue: string): string {
|
||||
}
|
||||
|
||||
async function fetchStats<T>(endpoint: string, from_date: string, to_date: string, extraParams: Record<string, string> = {}): Promise<T> {
|
||||
const fromDT = new Date(`${from_date}T00:00:00`).toISOString();
|
||||
const toDT = new Date(`${to_date}T23:59:59`).toISOString();
|
||||
const params = new URLSearchParams({ from_date: fromDT, to_date: toDT, ...extraParams });
|
||||
const params = new URLSearchParams({ from_date, to_date, ...extraParams });
|
||||
const response = await fetch(`${BASE_URL}/api/stats/${endpoint}?${params.toString()}`);
|
||||
if (!response.ok) throw new Error(`Failed to fetch ${endpoint}`);
|
||||
return response.json();
|
||||
@@ -44,18 +42,19 @@ export async function fetchSummary(from_date: string, to_date: string): Promise<
|
||||
return fetchStats('summary', from_date, to_date);
|
||||
}
|
||||
|
||||
export async function fetchDailySummary(from_date: string, to_date: string, day_start: string, day_end: string): Promise<DailySummaryResponse> {
|
||||
return fetchStats('daily-summary', from_date, to_date, { day_start, day_end });
|
||||
export async function fetchDailySummary(from_date: string, to_date: string, day_start: string, day_end: string, timezone_offset = 0): Promise<DailySummaryResponse> {
|
||||
return fetchStats('daily-summary', from_date, to_date, { day_start, day_end, timezone_offset: timezone_offset.toString() });
|
||||
}
|
||||
|
||||
export async function fetchTimetable(from_date: string, to_date: string, day_start: string, day_end: string): Promise<TimetableResponse> {
|
||||
return fetchStats('timetable', from_date, to_date, { day_start, day_end });
|
||||
export async function fetchTimetable(from_date: string, to_date: string, day_start: string, day_end: string, timezone_offset = 0): Promise<TimetableResponse> {
|
||||
return fetchStats('timetable', from_date, to_date, { day_start, day_end, timezone_offset: timezone_offset.toString() });
|
||||
}
|
||||
|
||||
export async function fetchWakeSleepTimes(from_date: string, to_date: string, wakeup_ref: string, bedtime_ref: string): Promise<WakeupBedtimeResponse> {
|
||||
export async function fetchWakeSleepTimes(from_date: string, to_date: string, wakeup_ref: string, bedtime_ref: string, timezone_offset = 0): Promise<WakeupBedtimeResponse> {
|
||||
return fetchStats('wake-sleep-times', from_date, to_date, {
|
||||
wakeup_ref: localHHMMToUTCHHMM(wakeup_ref),
|
||||
bedtime_ref: localHHMMToUTCHHMM(bedtime_ref)
|
||||
bedtime_ref: localHHMMToUTCHHMM(bedtime_ref),
|
||||
timezone_offset: timezone_offset.toString()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user