make calendar fetch time ranges respect user timezone

This commit is contained in:
Gregor Vostrak
2025-09-01 13:24:06 +02:00
parent e3bd50ed6b
commit f19abb9db6

View File

@@ -20,6 +20,7 @@ import { useProjectsStore } from '@/utils/useProjects';
import { useClientsStore } from '@/utils/useClients'; import { useClientsStore } from '@/utils/useClients';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { useTasksStore } from '@/utils/useTasks'; import { useTasksStore } from '@/utils/useTasks';
import { getUserTimezone } from '@/packages/ui/src/utils/settings';
const calendarStart = ref<Date | undefined>(undefined); const calendarStart = ref<Date | undefined>(undefined);
const calendarEnd = ref<Date | undefined>(undefined); const calendarEnd = ref<Date | undefined>(undefined);
@@ -28,15 +29,25 @@ const enableCalendarQuery = computed(() => {
return !!getCurrentOrganizationId() && !!calendarStart.value && !!calendarEnd.value; return !!getCurrentOrganizationId() && !!calendarStart.value && !!calendarEnd.value;
}); });
const formattedStartDate = computed(() => {
return calendarStart.value
? getDayJsInstance()(calendarStart.value).utc().tz(getUserTimezone(), true).utc().format()
: null;
});
const formattedEndDate = computed(() => {
return calendarEnd.value
? getDayJsInstance()(calendarEnd.value).utc().tz(getUserTimezone(), true).utc().format()
: null;
});
const { data: timeEntryResponse, isLoading: timeEntriesLoading } = useQuery<TimeEntryResponse>({ const { data: timeEntryResponse, isLoading: timeEntriesLoading } = useQuery<TimeEntryResponse>({
queryKey: computed(() => [ queryKey: computed(() => [
'timeEntry', 'timeEntry',
'calendar', 'calendar',
{ {
start: calendarStart.value start: formattedStartDate.value,
? getDayJsInstance()(calendarStart.value).utc().format() end: formattedEndDate.value,
: null,
end: calendarEnd.value ? getDayJsInstance()(calendarEnd.value).utc().format() : null,
organization: getCurrentOrganizationId(), organization: getCurrentOrganizationId(),
}, },
]), ]),
@@ -47,8 +58,8 @@ const { data: timeEntryResponse, isLoading: timeEntriesLoading } = useQuery<Time
organization: getCurrentOrganizationId() || '', organization: getCurrentOrganizationId() || '',
}, },
queries: { queries: {
start: getDayJsInstance()(calendarStart.value).utc().format(), start: formattedStartDate.value!,
end: getDayJsInstance()(calendarEnd.value).utc().format(), end: formattedEndDate.value!,
}, },
}), }),
}); });
@@ -109,8 +120,12 @@ function calculateNextRange(start: Date, end: Date): { start: Date; end: Date }
async function prefetchTimeEntries(start: Date, end: Date) { async function prefetchTimeEntries(start: Date, end: Date) {
if (!getCurrentOrganizationId()) return; if (!getCurrentOrganizationId()) return;
const startFormatted = getDayJsInstance()(start).utc().format(); const startFormatted = getDayJsInstance()(start)
const endFormatted = getDayJsInstance()(end).utc().format(); .utc()
.tz(getUserTimezone(), true)
.utc()
.format();
const endFormatted = getDayJsInstance()(end).utc().tz(getUserTimezone(), true).utc().format();
await queryClient.prefetchQuery({ await queryClient.prefetchQuery({
queryKey: [ queryKey: [